【问题标题】:Centering Text Horizontally and Vertically in LaTeX [closed]在 LaTeX 中水平和垂直居中文本 [关闭]
【发布时间】:2011-02-15 20:14:33
【问题描述】:

我想制作以下内容:

      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

【问题讨论】:

标签: latex tabular centering


【解决方案1】:

您可以创建一个新的列类型,或者在两个图像列的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

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • @Svante:是的。我在 Alexey 的回答中没有看到任何会导致 Latex 出现问题的内容。
    猜你喜欢
    • 2015-09-25
    • 2012-03-14
    • 2017-06-28
    • 1970-01-01
    • 2016-09-11
    • 1970-01-01
    • 2013-07-27
    • 2012-01-01
    相关资源
    最近更新 更多