表格:垂直对齐,高度可变

表格:垂直对齐,高度可变

我有以下代码

\usepackage{tabularx}
\begin{document}

\begin{table}[t]
\begin{center}
\renewcommand{\arraystretch}{1.3}
\begin{tabularx}{\textwidth}{crX}
\hline
\textbf{Chapter} & & \textbf{Reference} \\
\hline \\ \vspace{-11mm} \\
1 & \small{a} & \small{text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text} \\
\\ \vspace{-12mm} \\ \hline \\ \vspace{-12mm} \\
2 & \small{b} & \small{text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text} \\
\\ \vspace{-12mm} \\ \hline \\ \vspace{-12mm} \\
3 & \small{c} & \small{text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text} \\
\\ \vspace{-12mm} \\ \hline \\ \vspace{-12mm} \\
\end{tabularx}
\end{center}
\end{table}

\end{document}

从而产生了这个

在此处输入图片描述

现在,在第一列中,我希望“1”对齐在顶部,“2”对齐在中间,“3”对齐在底部。我该如何实现这一点?提前致谢。

答案1

这不是自动化的,但你没有说它必须是自动化的 (8^b)

我所做的是将长度定义\tmplength为表格内的行间距长度 (11pt),并使用\raisebox{-n\tmplength}{个数字}将 11pt 的 n 倍“数字”放置在顶行下方。此解决方案的手动部分是您必须计算参考“文本”的行数,以了解需要移动多少倍的\tmplength数字。

对于中间行,它需要向下移动2\tmplength才能到达子行 3,而对于第 3 行,则5\tmplength需要向下移动才能到达第 6 个子行。

感谢 David 绕过额外的包并直接进入\raisebox

编辑,我提供了另一种避免计算行数的替代方法,但它要求第三行不是 类型X,而是p具有指定宽度的类型。它还将第二列作为 完成,\llap这当然不是可取的也不是标准的。

\documentclass{article}
\usepackage{tabularx}
\newlength{\tmplength}
\begin{document}
Using X column in 3rd column

\begin{table}[ht]
\begin{center}
\def\stacktype{L}
\tmplength=11pt
\renewcommand{\arraystretch}{1.3}
\begin{tabularx}{\textwidth}{crX}
\hline
\textbf{Chapter} & & \textbf{Reference} \\
\hline \\ \vspace{-11mm} \\
1 & \small{a} & \small{text text text text text text text text text text text text text text text 
text text text text text text text text text text text text text text text text text text text text 
text text text} \\
\\ \vspace{-12mm} \\ \hline \\ \vspace{-12mm} \\
\raisebox{-2\tmplength}{2} & \small{b} & \small{text text text text text text text text text 
text text text text text text text text text text text text text text text text text text text text 
text text text text text text text text text text text text text text text text text text text text 
text text text text text text text text} \\
\\ \vspace{-12mm} \\ \hline \\ \vspace{-12mm} \\
\raisebox{-5\tmplength}{3} & \small{c} & \small{text text text text text text text text text 
text text text text text text text text text text text text text text text text text text text text 
text text text text text text text text text text text text text text text text text text text text 
text text text text text text text text text text text text text text text text text text text text 
text text text text text text text} \\
\\ \vspace{-12mm} \\ \hline \\ \vspace{-12mm} \\
\end{tabularx}
\end{center}
\end{table}

Alternate way, avoids counting, but must specify text-column width

\begin{table}[ht]
\begin{center}
\def\stacktype{L}
\tmplength=11pt
\renewcommand{\arraystretch}{1.3}
\begin{tabularx}{\textwidth}{cXp{3.64in}}
\hline
\textbf{Chapter} & & \textbf{Reference} \\
\hline \\ \vspace{-11mm} \\
1 & ~ & \parbox[t]{3.64in}{\strut\small\llap{a\hspace{0.4cm}}%
text text text text text text text text text text text text text text text text text text text text 
text text text text text text text text text text text text text text text text text text\strut} \\
\hline
2 & ~ & \parbox[c]{3.64in}{\strut\small\llap{b\hspace{0.4cm}}%
text text text text text text text text text text text text text text text text text text text text 
text text text text text text text text text text text text text text text text text text text text 
text text text text text text text text text text text text text text text text text\strut} \\[-0.4mm]
\hline
3 & ~ & \parbox[b]{3.64in}{\strut\small\llap{c\hspace{0.4cm}}%
text text text text text text text text text text text text text text text text text text text text 
text text text text text text text text text text text text text text text text text text text text 
text text text text text text text text text text text text text text text text text text text text 
text text text text text text text text text text text text text text text text\strut} \\[-1mm]
\hline 
\end{tabularx}
\end{center}
\end{table}
\end{document}

在此处输入图片描述

相关内容