在LaTeX中水平和垂直居中文本

17
我想要生成以下内容:
      a       b
    xxxxx   xxxxx
 1  xxxxx   xxxxx
    xxxxx   xxxxx

    xxxxx   xxxxx
 2  xxxxx   xxxxx
    xxxxx   xxxxx

这里的'x'块是图片,而'a'、'b'、'1'和'2'则是文本。

到目前为止,我已经尝试了两种方法:

\begin{figure}
\begin{center}
\begin{tabular}{ccc}
 & a & b \\
1 & \subfloat[]{\includegraphics[width=0.47\textwidth]{im.png}} &
    \subfloat[]{\includegraphics[width=0.47\textwidth]{im.png}} \\
2 & \subfloat[]{\includegraphics[width=0.47\textwidth]{im.png}} &
    \subfloat[]{\includegraphics[width=0.47\textwidth]{im.png}} \\
\end{tabular}
\end{center}
\end{figure}

这将产生:

      a       b
    xxxxx   xxxxx
    xxxxx   xxxxx
 1  xxxxx   xxxxx

    xxxxx   xxxxx
    xxxxx   xxxxx
 2  xxxxx   xxxxx

并且

\begin{figure}
\begin{center}
\begin{tabular}{m{1cm}m{6cm}m{6cm}}
 & a & b \\
1 & \subfloat[]{\includegraphics[width=0.47\textwidth]{im.png}} &
    \subfloat[]{\includegraphics[width=0.47\textwidth]{im.png}} \\
2 & \subfloat[]{\includegraphics[width=0.47\textwidth]{im.png}} &
    \subfloat[]{\includegraphics[width=0.47\textwidth]{im.png}} \\
\end{tabular}
\end{center}
\end{figure}

这将产生:

    a       b
    xxxxx   xxxxx
 1  xxxxx   xxxxx
    xxxxx   xxxxx

    xxxxx   xxxxx
 2  xxxxx   xxxxx
    xxxxx   xxxxx

对于未来的读者,请查看:http://tex.stackexchange.com/questions/12703/how-to-create-fixed-width-table-columns-with-text-raggedright-centered-raggedlef - Bernhard
2个回答

16

你可以创建一个新的列类型,或者在这两个图像列的m{6cm}前添加>{\centering\arraybackslash}

例如:

\newcolumntype{C}{>{\centering\arraybackslash} m{6cm} }  %# New column type
\begin{tabular}{m{1cm}CC}                                %# Table with two of them
...

>指令允许您在该列中的每个条目之前注入包含的代码。我们需要\arraybackslash来处理centering环境与tabular环境之间的不兼容性。[更多信息请点击这里。]1


4

我使用\dummyimage,因为我没有im.png。请将其替换为\includegraphics{im.png}

\font\dummyfont = cmr10 at 100pt
\def\dummyimage{{\vbox to 100pt{\vfil\hbox to 100pt{\hfil\dummyfont A\hfil}\vfil}}}

\hfil\vbox{
\halign{&\hfil\ $\vcenter{\hbox{#}}$\strut \ \hfil\cr
&a&b\cr 
1&\dummyimage&\dummyimage\cr
2&\dummyimage&\dummyimage\cr
}}

1
@Svante:是的。我没有看到Alexey的回答中有任何会在Latex中引起问题的内容。 - Charles Stewart

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接