我很难理解这里发生了什么:
我正在创建一个表格,并希望最左侧列的文本在其单元格中垂直居中。但是,垂直对齐似乎完全不一致。
这是我的代码(我必须添加填充文本,否则问题无法正确演示,如果看起来很乱,请见谅!)。我已尝试提供一个最小工作示例。
\documentclass{article}
\usepackage{multirow}
\usepackage{array}
\usepackage{ragged2e}
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}p{#1}}
\begin{document}
\begin{table}[htbp]
\caption{Sample Table.}\label{tab1}
\begin{tabular}{ |m{0.5cm}|P{4cm}|P{4.3cm}|P{4.5cm}| }
\hline
\textbf{} & \textbf{Objective} & \textbf{Criteria} & \textbf{Test Plan}\\
\hline
\multirow{7}{*}{\rotatebox{90}{Performance}} & Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler.\\ \cline{2-4}
&Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler. \\ \cline{2-4}
& & & \\ \cline{2-4}
& & & \\ \cline{2-4}
& & & \\ \cline{2-4}
& & & \\ \cline{2-4}
& & & \\ \hline
\multirow{2}{*}{\rotatebox{90}{Dimensions}} & Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler.\\ \cline{2-4}
& Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler.\\ \hline
\multirow{5}{*}{\rotatebox{90}{Safety}} & Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler.\\ \cline{2-4}
& & & \\ \cline{2-4}
& & & \\ \cline{2-4}
& & & \\ \cline{2-4}
& & & \\ \hline
\end{tabular}
\end{table}
\end{document}
这将生成下表,其中最左侧的单元格未正确垂直对齐。我该如何修复此问题?非常感谢!
答案1
单元格内容的垂直居中绝对不是小问题。但是,通常可以使用一些技巧(以美观的方式)解决它:
1)添加垂直位置校正:
改成\multirow{7}{*}
\multirow{7}{*}[-5ex]
改成\multirow{2}{*}
\multirow{2}{*}[-2.5ex]
改成\multirow{5}{*}
\multirow{5}{*}[-3ex]
2)(另一种方法)在 \multirow 语句中谎报行号:
改成\multirow{7}{*}
\multirow{11}{*}
改成\multirow{2}{*}
\multirow{6}{*}
改成\multirow{5}{*}
\multirow{7}{*}
答案2
multirow
通常适用于单行单元格;因此,如果是多行单元格,则必须计算行数,而不是行数。此外,您可以使用可选的垂直校正,如果是旋转材料,则选择旋转中心。
tabularx
无关:请注意,您的表格溢出到了边距。使用环境来获得适合边距之间的表格可能会很有趣。
\documentclass{article}
\usepackage{multirow, rotating, caption}
\usepackage{array}
\usepackage{ragged2e}
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}p{#1}}
\begin{document}
\begin{table}[htbp]
\caption{Sample Table.}\label{tab1}
\begin{tabular}{ |m{0.5cm}|P{4cm}|P{4.3cm}|P{4.5cm}| }
\hline
\textbf{} & \textbf{Objective} & \textbf{Criteria} & \textbf{Test Plan}\\
\hline
\multirow{11}{=}[0.5ex]{\rotatebox[origin =r]{90}{Performance}} & Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler.\\ \cline{2-4}
&Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler. \\ \cline{2-4}
& & & \\ \cline{2-4}
& & & \\ \cline{2-4}
& & & \\ \cline{2-4}
& & & \\ \cline{2-4}
& & & \\ \hline
\multirow{6}{=}{\rotatebox[origin =r]{90}{Dimensions}} & Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler.\\ \cline{2-4}
& Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler.\\ \hline
\multirow{7}{=}{\rotatebox[origin =c]{90}{Safety}} & Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler. & Filler text to demonstrate problem, filler filler filler filler filler.\\ \cline{2-4}
& & & \\ \cline{2-4}
& & & \\ \cline{2-4}
& & & \\ \cline{2-4}
& & & \\ \hline
\end{tabular}
\end{table}
\end{document}