多行单元格垂直对齐

多行单元格垂直对齐

我举一个小例子,这样更容易解释:

\documentclass[a4paper,12pt]{book}
\usepackage{multirow}
\usepackage{longtable}
\begin{document}
\begin{longtable}{|c|c|}
\hline
\parbox[b][2cm][t]{3cm}{Text1} & \multirow{2}{*}{Text 3} \\
\cline{1-1}
Text 2 & \\
\hline
\end{longtable}
\end{document}

两个单元格的高度不同,当我尝试将合并的单元格居中时,LaTeX 会将内容与分隔两个单元格的线对齐。我知道我可以使用\multirow命令中的固定偏移量来修复此对齐,但很多时候我必须“手动”完成此操作,因为每个单元格的大小都不同。是否可以自动将内容与合并单元格的实际中间对齐,而不是对齐\hline

答案1

在这里,我没有使用,而是在 中multirow嵌入。tabulartabular

\documentclass[a4paper,12pt]{book}
\usepackage{multirow}
\usepackage{longtable}
\begin{document}
NEW:
\begin{longtable}{|@{}c@{}|c|}
\hline
\begin{tabular}{p{3cm}}
Text1 \rule[-48pt]{0pt}{0pt}\\
\hline
\centering Text 2  
\end{tabular}
& Text 3 \\
\hline
\end{longtable}
ORIGINAL:
\begin{longtable}{|c|c|}
\hline
\parbox[b][2cm][t]{3cm}{Text1} & \multirow{2}{*}{Text 3} \\
\cline{1-1}
Text 2 & \\
\hline
\end{longtable}
\end{document}

在此处输入图片描述

相关内容