代码之家  ›  专栏  ›  技术社区  ›  Paul

文本在乳胶中水平和垂直居中[关闭]

  •  16
  • Paul  · 技术社区  · 15 年前

    我想提出以下建议:

          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
    
    2 回复  |  直到 15 年前
        1
  •  13
  •   Geoff    15 年前

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

    例如:

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

    这个 > 指令使您基本上可以在该列中的每个条目之前插入包含的代码。我们需要 \arraybackslash 处理 centering 环境和 tabular 环境。 More info can be found here.

        2
  •  4
  •   Svante    15 年前

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