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

在LaTeX中水平和垂直居中文本,latex,tabular,centering,Latex,Tabular,Centering,我想提出以下意见: 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

我想提出以下意见:

      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
    a       b
    xxxxx   xxxxx
 1  xxxxx   xxxxx
    xxxxx   xxxxx

    xxxxx   xxxxx
 2  xxxxx   xxxxx
    xxxxx   xxxxx

产生:

      a       b
    xxxxx   xxxxx
    xxxxx   xxxxx
 1  xxxxx   xxxxx

    xxxxx   xxxxx
    xxxxx   xxxxx
 2  xxxxx   xxxxx
    a       b
    xxxxx   xxxxx
 1  xxxxx   xxxxx
    xxxxx   xxxxx

    xxxxx   xxxxx
 2  xxxxx   xxxxx
    xxxxx   xxxxx

我使用
\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
}}

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

例如:

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

指令允许您在该列的每个条目之前插入包含的代码。我们需要
\arraybackslash
来处理
居中
环境和
表格
环境之间的不兼容性。[在这里可以找到更多信息。]

@Svante:是的。我在Alexey的回答中没有发现任何会导致乳胶出现问题的地方。对于未来的读者,请检查: