我正在使用创建一个表格booktabs
,但我还需要multirow
在特定位置结合长段文本。如果我multirow
正常使用,则无法拆分文本:
\usepackage{float}
\usepackage{booktabs}
\usepackage{multirow}
\begin{table}[H]
\small
\begin{tabular}{@{}p{1cm}p{5cm}p{6.5cm}p{2cm}@{}}
\toprule
\textbf{Ch.\#} & \textbf{Project title} & \textbf{Milestones} & \textbf{Expected date} \\ \midrule
3 & \multirow{4}{*}{This project will be an \newline extension of Ch. \#2. The code will be parallelized...}\\
& & Milestone 1 & 2019 \\
& & Milestone 2 & 2019 \\
& & Milestone 3 & 2019 \\ \midrule
4 & Title of project 4 & &\\
\bottomrule
\end{tabular}
\end{table}
如果我删除长文本周围的括号,它会保持单元格大小,但看起来格式错误,下一列中的多行会向下移动:
\usepackage{float}
\usepackage{booktabs}
\usepackage{multirow}
\begin{table}[H]
\small
\begin{tabular}{@{}p{1cm}p{5cm}p{6.5cm}p{2cm}@{}}
\toprule
\textbf{Ch.\#} & \textbf{Project title} & \textbf{Milestones} & \textbf{Expected date} \\ \midrule
3 & \multirow{4}{*} This project will be an \newline extension of Ch. \#2. The code will be parallelized...\\
& & Milestone 1 & 2019 \\
& & Milestone 2 & 2019 \\
& & Milestone 3 & 2019 \\ \midrule
4 & Title of project 4 & &\\
\bottomrule
\end{tabular}
\end{table}
对于这个特定情况,将这两个包结合起来的正确方法是什么?
答案1
Multirow 与 booktabs 完美配合。您只是忘记了使用参数{*}
指定多行宽度会使其只有一行。在具有预定义宽度的列中,请使用{=]
。
我冒昧地修改了您的序言,以改善表格的布局,特别是包装makecell
部分。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{float}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{ragged2e}
\usepackage{makecell}
\renewcommand{\theadfont}{\small\bfseries}
\begin{document}
\begin{table}[H]
\small\centering
\begin{tabular}{@{}lp{5cm}p{5cm}p{2cm}@{}}
\toprule
\thead{Ch.\#} & \thead{Project title} & \thead{Milestones} & \thead{Expected\\ date} \\ \midrule
3 & \multirow{4}{=}{\RaggedRight This project will be an extension of Ch. \#2. The code will be parallelized...}\\
& & Milestone 1 & 2019 \\
& & Milestone 2 & 2019 \\
& & Milestone 3 & 2019 \\ \midrule
4 & Title of project 4 & &\\
\bottomrule
\end{tabular}
\end{table}
\end{document}