我正在尝试弄清楚一些我找不到答案的事情。
我正在尝试创建一个表格,其中一行中的一些单元格需要有多行。我以为“多行”可以让我做到这一点,它确实可以做到,但它错误地将跨多行的数据垂直居中。参见附图 - 它最终太高了。
我意识到在我发送的示例中,我只能使用 3 行,顶部和底部为空,但在分割行数为偶数的情况下,该方法是不可行的。我还查看了多行文档,他们指定有一个微调参数,您可以在其中手动调整其高度。我不想这样做,因为如果我偏离一点点,它就不会对齐。另外,我想会有更好的方法。
这是 MWE
\documentclass[12pt,a4paper,twoside]{report}
%\usepackage[latin1]{inputenc} % shouldn't you be using 'utf8'?
\usepackage{amsmath}
%%%\usepackage{amsfonts} % is loaded automatically by 'amssymb'
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{array}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1\textwidth}}
\setlength{\textheight}{9in} % Height of the main body of the text
\setlength{\topmargin}{-.5in} % .5" margin on top of page
\setlength{\headsep}{.5in} % space between header and top of body
\addtolength{\headsep}{-\headheight} % See The LaTeX Companion, p 85
\setlength{\footskip}{.5in} % space between footer and bottom of body
\setlength{\textwidth}{6.25in} % width of the body of the text
\setlength{\oddsidemargin}{.25in} % 1.25" margin on the left for odd pages
\setlength{\evensidemargin}{0in} % 1.25" margin on the right for even pages
% Marginal notes
\setlength{\marginparwidth}{.75in} % width of marginal notes
\setlength{\marginparsep}{.125in} % space between marginal notes and text
\usepackage{booktabs}
\begin{document}
\begin{table}[ht]
\renewcommand{\arraystretch}{1.5}
\setlength\tabcolsep{0pt}
\caption[A caption]{A caption}
\label{tab-brachy-review}
\footnotesize
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}%
M{0.1}M{0.14}M{0.13}M{0.15}M{0.13}M{0.14}M{0.085}M{0.125}}
Refs & Site & Method & Sample Size & fractions & Delay (days) & BF and Perm & test \\ \midrule
Janssen & Te & 1 & 23 & 25 / 5 & Day 5\textsuperscript{a} & Increase & NSC \\ \midrule
\multirow{3}{*}{Coolens} & \multirow{3}{*}{Li} & \multirow{3}{*}{2} & \multirow{3}{*}{6} & \multirow{3}{*}{30-54 / 6} & Day 3\textsuperscript{a} & Increase & Increase \\ \cmidrule{6-8}
& & & & & 30 & Decrease & NSC \\ \cmidrule{6-8}
& & & & & 60 & Decrease & NSC \\ \cmidrule{6-8}
Janssen & Te & 1 & 23 & 25 / 5 & Day 5\textsuperscript{a} & Increase & NSC \\ \bottomrule
\end{tabular*}
\end{table}
\end{document}
答案1
首先,您需要知道 abooktab
与普通表格到底有何不同。具体来说,在规则的下方和上方添加了两个空格,\belowrulesep=.65ex
并且\aboverulesep=.4ex
。这些额外的垂直空格破坏了 的工作\multirow
,不过幸运的是,正如您所提到的,还有一个额外的选项\multirow
可用于弥补这一点。
规则是这样的:如果n
中有行\multirow
,那么您需要将内容降低n/2 * (0.65ex + 0.4ex) = n/2 * 1.05ex
,或者简单地0.525*n
。在我们的例子中,这是0.525*3ex = 1.5750ex
。因此,只需进行数学运算或使用\dimexpr
来计算此维度并将其负数添加到 的选项中\multirow
。
\documentclass[12pt,a4paper,twoside]{report}
%\usepackage[latin1]{inputenc} % shouldn't you be using 'utf8'?
\usepackage{amsmath}
%%%\usepackage{amsfonts} % is loaded automatically by 'amssymb'
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{array}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1\textwidth}}
\setlength{\textheight}{9in} % Height of the main body of the text
\setlength{\topmargin}{-.5in} % .5" margin on top of page
\setlength{\headsep}{.5in} % space between header and top of body
\addtolength{\headsep}{-\headheight} % See The LaTeX Companion, p 85
\setlength{\footskip}{.5in} % space between footer and bottom of body
\setlength{\textwidth}{6.25in} % width of the body of the text
\setlength{\oddsidemargin}{.25in} % 1.25" margin on the left for odd pages
\setlength{\evensidemargin}{0in} % 1.25" margin on the right for even pages
% Marginal notes
\setlength{\marginparwidth}{.75in} % width of marginal notes
\setlength{\marginparsep}{.125in} % space between marginal notes and text
\usepackage{booktabs}
\begin{document}
\begin{table}[ht]
\renewcommand{\arraystretch}{1.5}
\setlength\tabcolsep{0pt}
\caption[A caption]{A caption}
\label{tab-brachy-review}
\footnotesize
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}%
M{0.1}M{0.14}M{0.13}M{0.15}M{0.13}M{0.14}M{0.085}M{0.125}}
Refs & Site & Method & Sample Size & fractions & Delay (days) & BF and Perm & test \\ \midrule
Janssen & Te & 1 & 23 & 25 / 5 & Day 5\textsuperscript{a} & Increase & NSC \\ \midrule
\multirow{3}{*}[-1.575ex]{Coolens} & \multirow{3}{*}[-1.575ex]{Li} & \multirow{3}{*}[-1.575ex]{2} & \multirow{3}{*}[-1.575ex]{6} & \multirow{3}{*}[-1.575ex]{30-54 / 6} & Day 3\textsuperscript{a} & Increase & Increase \\ \cmidrule{6-8}
& & & & & 30 & Decrease & NSC \\ \cmidrule{6-8}
& & & & & 60 & Decrease & NSC \\ \cmidrule{6-8}
Janssen & Te & 1 & 23 & 25 / 5 & Day 5\textsuperscript{a} & Increase & NSC \\ \bottomrule
\end{tabular*}
\end{table}
\end{document}