多行单元格中的线条垂直分布均匀

多行单元格中的线条垂直分布均匀

我正在尝试创建一个图形,其中右侧有两三张照片,左侧有文字。我想要的是左侧的文本均匀分布在单元格的高度(等于照片的高度)。这是我的 MWE:

\documentclass{scrartcl}

\usepackage{graphicx}
\usepackage{makecell}


\begin{document}
        \begin{figure}
              \begin{tabular}{ccc}
                        \makecell[cc]{line 1 \\ line 2 \\ line 3 \\} & \makecell[cc]{\includegraphics[width=0.5 \textwidth]{example-image-a}\\ text below image A} & \makecell[cc]{\includegraphics[width=0.5 \textwidth]{example-image-b}\\ text below image b}\\
                        \makecell[cc]{line 1 \\ line 2 \\ line 3 \\} & \makecell[cc]{\includegraphics[width=0.5 \textwidth]{example-image-a}\\ text below image A} & \makecell[cc]{\includegraphics[width=0.5 \textwidth]{example-image-b}\\ text below image b}\\
                \end{tabular}
                \caption{caption of the whole figure}
        \end{figure}
\end{document}

我尝试过\vfill这样使用:

\makecell[cc]{\vfill line1 \\ \vfill line2 \\ \vfill line3\\}

但这样我就得到了一个错误,提示“缺少 \endgroup 插入”。\\在我看来,在行间使用 more 似乎非常不方便。

如何最好地让左侧三行文本的下方、上方和之间拥有相等的空间?

答案1

展示比解释更容易。顺便说一句,我也尝试过使用\\[\fill]\makecell但没有成功。

\documentclass{scrartcl}

\usepackage{graphicx}
\usepackage{makecell}
\usepackage{showframe}% debugging tool

\begin{document}
        \begin{figure}
           \sbox0{\includegraphics[width=0.4 \textwidth]{example-image-a}}%
           \sbox1{\includegraphics[width=0.4 \textwidth]{example-image-b}}%
              \begin{tabular}{ccc}
                \parbox[c][\dimexpr \ht0+\normalbaselineskip][s]{\dimexpr 0.2\textwidth - 6\tabcolsep}%
                  {\centering line 1 \\[\fill] line 2 \\[\fill] line 3 \\[\fill]} & 
                    \makecell[cc]{\usebox0 \\ text below image A} & 
                    \makecell[cc]{\usebox1 \\ text below image b}\\
                        \makecell[cc]{line 1 \\[\fill] line 2 \\[\fill] line 3 \\[\fill]} & \makecell[cc]{\includegraphics[width=0.4 \textwidth]{example-image-a}\\ 
                        text below image A} & \makecell[cc]{\includegraphics[width=0.4 \textwidth]{example-image-b}\\ text below image b}\\
                \end{tabular}
                \caption{caption of the whole figure}
        \end{figure}
\end{document}

此版本测量一次性表格中文本的宽度,然后计算图像的宽度以填充剩余空间。

\documentclass{scrartcl}

\usepackage{graphicx}
\usepackage{makecell}
\usepackage{showframe}% debugging tool

\newlength{\tempdima}% \dimen0 doesn't work here

\begin{document}
        \begin{figure}
          \sbox0{\begin{tabular}{@{}c@{}} line 1 \\ line 2 \\ line 3 \end{tabular}}% measure width of text
          \setlength{\tempdima}{\dimexpr 0.5\textwidth - 3\tabcolsep - 0.5\wd0}%
          \sbox1{\includegraphics[width=\tempdima]{example-image-a}}% measure height of image
          \sbox2{\includegraphics[width=\tempdima]{example-image-b}}% measure height of image
          \dimen1=\ht1
          \ifdim\ht2>\ht1 \dimen1=\ht2 \fi
          \advance\dimen1 by \arraystretch\baselineskip
          \begin{tabular}{ccc}
            \parbox[c][\dimen1][s]{\wd0}%
              {\centering line 1 \\[\fill] line 2 \\[\fill] line 3 \\[\fill] \hrule} & 
                \makecell[cc]{\usebox1 \\ text below image A} & 
                \makecell[cc]{\usebox2 \\ text below image b}\\
            \makecell[cc]{line 1 \\[\fill] line 2 \\[\fill] line 3 \\[\fill]} & \makecell[cc]{\includegraphics[width=\tempdima]{example-image-a}\\ 
              text below image A} & \makecell[cc]{\includegraphics[width=\tempdima]{example-image-b}\\ text below image b}\\
            \end{tabular}
          \caption{caption of the whole figure}
        \end{figure}
\end{document}

答案2

minipage一个更简单的解决方案是在 a 中使用 atabular并适应@karlkoeller 的回答上一个问题在这个修改过的例子中,计算了高度和宽度以避免过满hbox

\documentclass{scrartcl}

\usepackage{graphicx, ragged2e, array, calc}

\newlength{\picheight} % height of picture, use same height on the minipage
\newlength{\cwidth} % calculate the width of columns, use same width for the picture

\newcolumntype{T}{>{\small\RaggedRight\small\hspace{0pt}}m{\textwidth-(2\cwidth+4\tabcolsep)}}
\newcolumntype{P}{>{\centering\arraybackslash}m{\cwidth}}

\begin{document}

\settowidth{\cwidth}{\includegraphics[width=0.45\textwidth-2\tabcolsep]{example-image-a}}
\settototalheight{\picheight}{\includegraphics[width=\cwidth]{example-image-a}}

\begin{figure}

\begin{tabular}{@{}TPP@{}}

\begin{minipage}[b][\picheight][s]{\linewidth} % minipage has same height as the pictures
\setlength{\baselineskip}{\dimexpr\baselineskip plus 50pt}%
I am trying to create a figure or something nice to write.%
\end{minipage}
& \includegraphics[width=\cwidth]{example-image-a} 
& \includegraphics[width=\cwidth]{example-image-b}\\
& text below image A & text below image B \\
 \begin{minipage}[b][\picheight][s]{\linewidth}
\setlength{\baselineskip}{\dimexpr\baselineskip plus 50pt}%
Here, I am trying to write some interesting words regarding a figure or something.%
\end{minipage}
& \includegraphics[width=\cwidth]{example-image-a} 
& \includegraphics[width=\cwidth]{example-image-b}\\
& text below image C & text below image D \\
 \end{tabular}
\caption{Caption of the whole figure}
\end{figure}
 \end{document}

在此处输入图片描述

相关内容