我正在努力解决以下问题。假设我有以下示例代码:
\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}
这是你的本意吗?