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

Pau*_*aul 17 latex tabular centering

我想制作以下内容:

      a       b
    xxxxx   xxxxx
 1  xxxxx   xxxxx
    xxxxx   xxxxx

    xxxxx   xxxxx
 2  xxxxx   xxxxx
    xxxxx   xxxxx
Run Code Online (Sandbox Code Playgroud)

'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}
Run Code Online (Sandbox Code Playgroud)

哪个产生:

      a       b
    xxxxx   xxxxx
    xxxxx   xxxxx
 1  xxxxx   xxxxx

    xxxxx   xxxxx
    xxxxx   xxxxx
 2  xxxxx   xxxxx
Run Code Online (Sandbox Code Playgroud)

\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}
Run Code Online (Sandbox Code Playgroud)

哪个产生:

    a       b
    xxxxx   xxxxx
 1  xxxxx   xxxxx
    xxxxx   xxxxx

    xxxxx   xxxxx
 2  xxxxx   xxxxx
    xxxxx   xxxxx
Run Code Online (Sandbox Code Playgroud)

Geo*_*off 13

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

例如:

\newcolumntype{C}{>{\centering\arraybackslash} m{6cm} }  %# New column type
\begin{tabular}{m{1cm}CC}                                %# Table with two of them
...
Run Code Online (Sandbox Code Playgroud)

>指令允许您基本上在该列中的每个条目之前注入包含的代码.我们需要\arraybackslash处理centering环境与tabular环境之间的不兼容问题.更多信息可以在这里找到.