我想画一个像这样的表格
我使用该m
参数是因为表的其余行需要它。
但是如果我使用\multirow
命令来合并一些行,m
列的参数将不会生效并产生错误。
\documentclass{article}
\usepackage{booktabs,multirow,array}
\newcolumntype{N}{@{}m{0pt}@{}}%a fix for array package
\begin{document}
\begin{table}
\begin{tabular}{m{4cm}m{2cm}m{4cm}N}
\toprule[1pt]
&\multirow{5}*{a very,\\
very long\\
text across\\
five lines\\
as above}
&\multirow{4}*{a longer\\
text\\
across\\
four lines}\\\cmidrule{1-1}
&&\\\cmidrule{1-1}
long text in first column&&\\\cmidrule{1-1}
&&\\\cmidrule{1-1}
&&\\\bottomrule[1pt]
\end{tabular}\end{table}
\end{document}
答案1
正如文档中提到的那样,multirow
您可以使用*
多行内容,条件是该多行内容包装在表格或数组中。
这就是我在这里所做的。我通过添加额外的垂直空间,\ExtraSep
以便这些行与全局表格中的行连续。我使用了包中的维度booktabs
(它们在文件中以清晰的名称列出,.log
因此我可以猜出它们的含义)。
\documentclass[border=12pt]{standalone}
\usepackage{booktabs,multirow,array}
\newcolumntype{N}{@{}m{0pt}@{}}%a fix for array package
\newcommand\ExtraSep
{\dimexpr\cmidrulewidth+\aboverulesep+\belowrulesep\relax}
\begin{document}
\begin{tabular}{m{4cm}m{2cm}m{4cm}N}
\toprule[1pt]
&\multirow{5}*{\begin{tabular}{l}a very,\\[\ExtraSep]
very long\\[\ExtraSep]
text across\\[\ExtraSep]
five lines\\[\ExtraSep]
as above
\end{tabular}}
&\multirow{4}*{\begin{tabular}{l}
a longer\\[\ExtraSep]
text\\[\ExtraSep]
across\\[\ExtraSep]
four lines\end{tabular}}\\\cmidrule{1-1}
&&\\\cmidrule{1-1}
long text in first column&&\\\cmidrule{1-1}
&&\\\cmidrule{1-1}
&&\\\bottomrule[1pt]
\end{tabular}
\end{document}
答案2
如果要在里面使用换行符,\multirow
则必须指定固定宽度。还请注意,\multirow
在这种情况下,除非您进行一些手动调整,否则不会产生所需的结果,如下例所示:
\documentclass{article}
\usepackage{booktabs,multirow,array}
\newcolumntype{N}{@{}m{0pt}@{}}%a fix for array package
\begin{document}
\begin{table}
\begin{tabular}{m{4cm}m{2cm}m{4cm}N}
\toprule[1pt]
&\multirow{5}{2cm}{a very,\\[.4\baselineskip]
very long\\[.4\baselineskip]
text across\\[.4\baselineskip]
five lines\\[.4\baselineskip]
as above}
&\multirow{5}[8]{4cm}{a longer\\[.4\baselineskip]
text\\[.4\baselineskip]
across\\[.4\baselineskip]
four lines}\\\cmidrule{1-1}
&\\\cmidrule{1-1}
long text in first column&&\\\cmidrule{1-1}
&&\\\cmidrule{1-1}
&&\\\bottomrule[1pt]
\end{tabular}
\end{table}
\end{document}
输出:
编辑
如果你正在使用
\renewcommand{\arraystretch}{0.5}
需要进行以下调整
\documentclass{article}
\usepackage{booktabs,multirow,array}
\newcolumntype{N}{@{}m{0pt}@{}}%a fix for array package
\begin{document}
\begin{table}\renewcommand{\arraystretch}{0.5}
\begin{tabular}{m{4cm}m{2cm}m{4cm}N}
\toprule[1pt]
&\multirow{5}{2cm}[.5ex]{a very,\\[.1ex]
very long\\[.1ex]
text across\\[.1ex]
five lines\\[.1ex]
as above}
&\multirow{5}{4cm}[-1ex]{a longer\\[.1ex]
text\\[.1ex]
across\\[.1ex]
four lines}\\\cmidrule{1-1}
&\\\cmidrule{1-1}
long text in first column&&\\\cmidrule{1-1}
&&\\\cmidrule{1-1}
&&\\\bottomrule[1pt]
\end{tabular}
\end{table}
\end{document}