我的垂直线被水平线打断了(中断)booktabs
。我该如何修复?
说使用很好\hline
,但我还需要一个仅跨越后两列的,据我所知cmidrule
没有等效项。而且很丑陋,因为它不会自动在行与前一行/后一行文本之间留下任何垂直空间。\hline
\hline
\documentclass[a4paper,12pt]{article}
\date{}
\usepackage{a4wide}
\usepackage{booktabs} %for top, middle and bottomline
\usepackage{multirow} %multi column and row spanning
\usepackage{amsmath}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{multicol}
\usepackage{blindtext}
\begin{document}
\begin{multicols}{2}
\subsection*{Results}
\resizebox{\columnwidth}{!}{%
\begin{tabular}{@{} l | c | c @{}}
\toprule
Characteristic & \multicolumn{2}{c}{Result}\\
\cmidrule{2-3}
& Seaweed isolate & Coral isolate \\
\midrule
Cell shape & Rod & Rod\\
Gram stain & $-$ & $-$\\
Oxidase & $+$ & $-$\\
Catalase & $+$ & $-$\\
MSA & Growth & No growth\\
Anaerobic & Growth (weak) & No growth\\
Motility & & \\
Indole production & & \\
Hugh \& Leifsons & & \\
\bottomrule
\end{tabular}
}
\blindtext
{\noindent
\begin{tabularx}{\columnwidth}
{ | l | >{\raggedright\arraybackslash} X | >{\centering\arraybackslash} X | }
Leave this column alone. & Left justify and adjust this column. &
Centre and adjust this column. \\
\end{tabularx}
}
\end{multicols}
\end{document}
答案1
您可以使用包\extrarowheight
中的命令array
来拉伸所有行。否则,您可以定义自己的“strut”命令来放大单行。下面的代码基于 的array
strut 框。如果您使用垂直线,那么也可以在侧面使用它。
编辑:还有比格斯特鲁特包裹
我还包括一个例子,如何正确地做到这一点booktabs
\documentclass{article}
\usepackage{array}
%\setlength{\extrarowheight}{1pt}
\usepackage{booktabs} %for top, middle and bottomline
\usepackage{bigstrut}
\setlength\bigstrutjot{3pt}
\makeatletter
\newlength\mylena
\newlength\mylenb
\newcommand\mystrut[1][2]{%
\setlength\mylena{#1\ht\@arstrutbox}%
\setlength\mylenb{#1\dp\@arstrutbox}%
\rule[\mylenb]{0pt}{\mylena}}
\makeatother
\begin{document}
\noindent With mystrut\par
\bigskip
\begin{tabular}{|l|c|c|}
\hline
\mystrut & \multicolumn{2}{c|}{Result}\\
\cline{2-3}
\mystrut
Characteristic & Seaweed isolate & Coral isolate \\
\hline
\mystrut
Cell shape & Rod & Rod\\
Gram stain & $-$ & $-$\\
Oxidase & $+$ & $-$\\
Catalase & $+$ & $-$\\
MSA & Growth & No growth\\
Anaerobic & Growth (weak) & No growth\\
Motility & & \\
Indole production & & \\
Hugh \& Leifsons & & \\
\hline
\end{tabular}
\bigskip
\noindent With bigstrut\par
\bigskip
\begin{tabular}{|l|c|c|}
\hline
\bigstrut & \multicolumn{2}{c|}{Result}\\
\cline{2-3}
\bigstrut
Characteristic & Seaweed isolate & Coral isolate \\
\hline
\bigstrut[t]
Cell shape & Rod & Rod\\
Gram stain & $-$ & $-$\\
Oxidase & $+$ & $-$\\
Catalase & $+$ & $-$\\
MSA & Growth & No growth\\
Anaerobic & Growth (weak) & No growth\\
Motility & & \\
Indole production & & \\
\bigstrut[b]
Hugh \& Leifsons & & \\
\hline
\end{tabular}
\bigskip
\noindent With booktabs\par
\bigskip
\begin{tabular}{@{}lcc@{}}
\toprule
& \multicolumn{2}{c@{}}{Result}\\
\cmidrule(l){2-3}
Characteristic & Seaweed isolate & Coral isolate \\
\cmidrule( r){1-1}
\cmidrule(lr){2-2}
\cmidrule(l ){3-3}
Cell shape & Rod & Rod\\
Gram stain & $-$ & $-$\\
Oxidase & $+$ & $-$\\
Catalase & $+$ & $-$\\
MSA & Growth & No growth\\
Anaerobic & Growth (weak) & No growth\\
Motility & & \\
Indole production & & \\
Hugh \& Leifsons & & \\
\bottomrule
\end{tabular}
\end{document}
输出为
答案2
如果您确实想将垂直规则与 规则一起使用booktabs
(这完全不符合 的精神booktabs
),则可以{NiceTabular}
使用nicematrix
。
\documentclass[a4paper,12pt]{article}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{nicematrix}
\begin{document}
\begin{NiceTabular}{@{} l | c | c @{}}
\toprule
Characteristic & \multicolumn{2}{c}{Result}\\
\cmidrule{2-3}
& Seaweed isolate & Coral isolate \\
\midrule
Cell shape & Rod & Rod\\
Gram stain & $-$ & $-$\\
Oxidase & $+$ & $-$\\
Catalase & $+$ & $-$\\
MSA & Growth & No growth\\
Anaerobic & Growth (weak) & No growth\\
Motility & & \\
Indole production & & \\
Hugh \& Leifsons & & \\
\bottomrule
\end{NiceTabular}
\end{document}
您需要多次编译(因为nicematrix
在后台使用 PGF/Tikz 节点)。
答案3
booktabs
环境的替代解决方案tabularray
包装:书标和垂直规则可以很好地协同工作。
\documentclass[a4paper,12pt]{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}
\begin{booktabs}{@{} l | c | c @{}}
\toprule
Characteristic & \SetCell[c=2]{c} Result \\
\cmidrule{2-3}
& Seaweed isolate & Coral isolate \\
\midrule
Cell shape & Rod & Rod\\
Gram stain & $-$ & $-$\\
Oxidase & $+$ & $-$\\
Catalase & $+$ & $-$\\
MSA & Growth & No growth\\
Anaerobic & Growth (weak) & No growth\\
Motility & & \\
Indole production & & \\
Hugh \& Leifsons & & \\
\bottomrule
\end{booktabs}
\end{document}