我正在尝试创建一个表格,其中一些列应该居中(垂直)对齐,而另一些列应该位于顶部。使用“m”列类型进行垂直居中似乎会影响 p 类型的列。(我确实知道 newcolumncommand,我只是用它作为一个简单的例子)。
\documentclass{article}
\usepackage{array}
\begin{document}
\begin{tabular}{|p{0.2\textwidth}|>{\centering\arraybackslash}m{0.2\textwidth}|>{\centering\arraybackslash}m{0.08\textwidth}|} \hline
I am not at the top of this cell & Longer Line that is centred and wrapped, and appears in the correct place & Small \\ \hline
\end{tabular}
\end{document}
我真正想要的是更像这样的东西:
我通常喜欢使用 tabu 而不是 tabular,我在那里遇到了与使用 tabular 类似的麻烦。
有人有简单的解决方案吗?谢谢。
答案1
另一种解决方案也需要手动调整最终布局:
\documentclass{article}
\usepackage{array, makecell, multirow}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcommand\mrc[2]{\multirowcell{#1}{#2}}% #1 number of lines in the tallest cell
\begin{document}
\begin{tabular}{|p{0.2\textwidth}|P{0.3\textwidth}|P{0.2\textwidth}|}
\hline
I am at the top of this cell
& Longer Line that is centered and wrapped,
and appears in the correct place of this
LibreOffice Writer table, started at the top of cell
& \mrc{7}{Small} \\ % <-- the tallest cell has 7 lines ...
\hline
\end{tabular}
\end{document}
答案2
\documentclass{article}
\usepackage{array}
\begin{document}
\begin{tabular}{|p{0.2\textwidth}|>{\centering\arraybackslash}m{0.3\textwidth}|>{\centering\arraybackslash}m{0.2\textwidth}|} \hline
\vspace{-1.35cm}I am not at the top of this cell & Longer Line that is centred and wrapped, and appears in the correct place of this LibreOffice Writer table & Small \\ \hline
\end{tabular}
\end{document}