![表格中单元格第一行、第一列没有垂直居中](https://linux22.com/image/373119/%E8%A1%A8%E6%A0%BC%E4%B8%AD%E5%8D%95%E5%85%83%E6%A0%BC%E7%AC%AC%E4%B8%80%E8%A1%8C%E3%80%81%E7%AC%AC%E4%B8%80%E5%88%97%E6%B2%A1%E6%9C%89%E5%9E%82%E7%9B%B4%E5%B1%85%E4%B8%AD.png)
我正在努力解决以下问题。假设我有以下示例代码:
\documentclass{article}
\usepackage{array, booktabs}
\usepackage{multirow}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
\begin{table}
\centering
\begin{tabular}{P{2cm} | P{4cm} | P{4cm} | P{2cm}}
\toprule
\multirow{2}{*}{\begin{tabular}[c]{@{}c@{}}Line 1\\Line 2\\Line 3\end{tabular}}
&
{\begin{tabular}[c]{@{}c@{}}Line 1\\Line 2\\Line 3\end{tabular}}
&
{\begin{tabular}[c]{@{}c@{}}Line 1\\Line 2\\Line 3\end{tabular}}
&
\multirow{2}{*}{\begin{tabular}[c]{@{}c@{}}Line 1\\Line 2\end{tabular}}
\\
& \textit{Lorem ipsum dolor sit} & \textit{Lorem ipsum dolor sit} & \\
\toprule
A & Lorem ipsum dolor sit & Lorem ipsum dolor sit & B \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
产生以下输出:
我的问题:在第一行、第一列中,我还想让三条线垂直居中。如何实现?!
提前谢谢你的帮助!
答案1
您可以使用\makecell
或不使用垂直线booktabs
:
\documentclass{article}
\usepackage{array, booktabs}
\usepackage{makecell}
\newcolumntype{P}[1]{>{\centering\leavevmode\arraybackslash}p{#1}}
\begin{document}
\begin{table}
\centering
\begin{tabular}{P{2cm} P{4cm} P{4cm} P{2cm}}
\toprule
\makecell{Line 1\\Line 2\\Line 3}
&
\makecell{Line 1\\Line 2\\Line 3\\ \textit{Lorem ipsum dolor sit}}
&
\makecell{Line 1\\Line 2\\Line 3\\ \textit{Lorem ipsum dolor sit}}
&
\makecell{Line 1\\Line 2}
\\
\toprule
A & Lorem ipsum dolor sit & Lorem ipsum dolor sit & B \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
这是你的本意吗?