如何格式化列联表的规则?
该表格仍应符合我使用 booktabs 包创建的其他表格的外观。
我正在使用 booktabs 包,通常遵循不使用垂直规则的规则,但在这种情况下我需要一个。
下面是使用一个中间规则和一个垂直规则的代码:
\documentclass{article}
\usepackage{booktabs}
\usepackage{threeparttable}
\begin{document}
\begin{table}[h!]
\begin{threeparttable}
\caption{name}
\begin{tabular}{c|ccccccc}
\toprule
& B & C & D & E & F & G & H\\
\midrule
A & 1 & 2 & 3 & 4 & 5 & 6 & 7\\
B & & 9 & 0 & 1 & 2 & 3 & 4\\
C & & & 5 & 6 & 7 & 8 & 9\\
D & & & & 0 & 1 & 2 & 3\\
E & & & & & 4 & 5 & 6\\
F & & & & & & 7 & 8\\
G & & & & & & & 9\\
\bottomrule
\end{tabular}
\begin{tablenotes}\footnotesize
\item[] notes
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
答案1
另外两种可能性:
\documentclass{article}
\usepackage[flushleft]{threeparttable}
\usepackage[table, svgnames]{xcolor}
\usepackage{boldline, cellspace}
\setlength\cellspacetoplimit{1.5ex}
\setlength\cellspacebottomlimit{1.3ex}
\renewcommand\TPTtagStyle{\itshape}
%% Define a few struts
%% (from code by Claudio Beccari in TeX and TUG News, Vol. 2, 1993)
\newcommand\Tstrut{\rule{0pt}{2.7ex}} % "top" strut
\newcommand\Bstrut{\rule[-1.1ex]{0pt}{0pt}} % "bottom" strut
\newcommand\TBstrut{\Tstrut\Bstrut} % "top and bottom" strut
\begin{document}
\begin{table}[h!]
\centering
\begin{threeparttable}
\caption{Name}
\begin{tabular}{cV{3}*{7}{Sc}V{1.8}}
& B\tnote{a} & C & D & E & F & G & H \\
\hlineB{3}
A & 1 & 2 & 3 & 4 & 5 & 6 & 7 \\
B & & 9 & 0 & 1 & 2 & 3 & 4 \\
C & & & 5 & 6 & 7 & 8 & 9 \\
D & & & & 0 & 1 & 2 & 3 \\
E & & & & & 4 & 5 & 6 \\
F & & & & & & 7 & 8 \\
G\tnote{b} & & & & & & & 9 \\
\clineB{1-8}{1.8}
\end{tabular}
\footnotesize
\begin{tablenotes}
\item[a] The letter ``B'' is very important.
\item[b] So is the letter ``G''.
\end{tablenotes}
\end{threeparttable}
\end{table}
\begin{table}[h!]
\centering
\begin{threeparttable}
\caption{Name}
\begin{tabular}{>{\columncolor{Gainsboro!50}}c!{\hspace{0.4em}}*{7}{Sc}|}
\rowcolor{Gainsboro!50} \cellcolor{Yellow!60!OrangeRed!32! } & B\tnote{a} & C & D & E & F & G & \multicolumn{1}{c}{H} \\
\noalign{\vspace{0.5ex}}
A & 1 & 2 & 3 & 4 & 5 & 6 & 7 \\
B & & 9 & 0 & 1 & 2 & 3 & 4 \\
C & & & 5 & 6 & 7 & 8 & 9 \\
D & & & & 0 & 1 & 2 & 3 \\
E & & & & & 4 & 5 & 6 \\
F & & & & & & 7 & 8 \\
G\tnote{b} & & & & & & & 9 \\
\cline{2-8}
\end{tabular}
\footnotesize
\begin{tablenotes}
\item[a] The letter ``B'' is very important.
\item[b] So is the letter ``G''.
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
更新:
我建议对tablenotes
OP 解决方案的一部分进行一些改进,使用以下para
选项(带有一个小补丁):
\documentclass[preview, border={10pt 10pt -180pt 10pt}]{standalone}
\usepackage{booktabs}
\usepackage{threeparttable}
\usepackage{xpatch}
\makeatletter
\xpatchcmd{\TPT@doparanotes}{%
\hskip 1em\@plus .3em}{%
\hskip 0.75em\@plus .25em}
\makeatother
%% Define a few struts
%% (from code by Claudio Beccari in TeX and TUG News, Vol. 2, 1993)
\newcommand\Tstrut{\rule{0pt}{2.7ex}} % "top" strut
\begin{document}
\begin{table}[h!]
\begin{threeparttable}
\caption{Name}
\begin{tabular}{c|*{7}{c}}
\toprule
& B & C & D & E & F & G & H\\
\hline
A & 1 & 2 & 3 & 4 & 5 & 6 & 7\Tstrut\\
B & & 9 & 0 & 1 & 2 & 3 & 4\\
C & & & 5 & 6 & 7 & 8 & 9\\
D & & & & 0 & 1 & 2 & 3\\
E & & & & & 4 & 5 & 6\\
F & & & & & & 7 & 8\\
G & & & & & & & 9\\
\bottomrule
\end{tabular}
\begin{tablenotes}[para, online]\footnotesize%
\def\tnote#1{\protect\TPToverlap{\TPTtagStyle{#1}}}%
\item[A]--- Apple,
\item[B]--- Banana,
\item[C]--- Cherry,
\item[D]--- Date,
\item[E]--- Elderberry,
\item[F]--- Fig,
\item[G]--- Grape,
\item[H]--- Honeydew melon.
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
答案2
由于垂直规则似乎是必要的,我建议你不是使用包的宏booktabs
。为了在 创建的水平规则上方和下方获得足够的间距\hline
,我建议您插入印刷支柱,如下例所示。
\documentclass{article}
\usepackage[flushleft]{threeparttable}
\renewcommand\TPTtagStyle{\itshape}
%% Define a few struts
%% (from code by Claudio Beccari in TeX and TUG News, Vol. 2, 1993)
\newcommand\Tstrut{\rule{0pt}{2.7ex}} % "top" strut
\newcommand\Bstrut{\rule[-1.1ex]{0pt}{0pt}} % "bottom" strut
\newcommand\TBstrut{\Tstrut\Bstrut} % "top and bottom" strut
\begin{document}
\begin{table}[h!]
\renewcommand\arraystretch{1.25}
\begin{threeparttable}
\caption{Name}
\begin{tabular}{|c|ccccccc|}
\hline
& B\tnote{a} & C & D & E & F & G & H\TBstrut\\
\hline
A & 1 & 2 & 3 & 4 & 5 & 6 & 7\Tstrut\\
B & & 9 & 0 & 1 & 2 & 3 & 4\\
C & & & 5 & 6 & 7 & 8 & 9\\
D & & & & 0 & 1 & 2 & 3\\
E & & & & & 4 & 5 & 6\\
F & & & & & & 7 & 8\\
G\tnote{b} & & & & & & & 9\Bstrut\\
\hline
\end{tabular}
\footnotesize
\begin{tablenotes}
\item[a] The letter ``B'' is very important.
\item[b] So is the letter ``G''.
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
答案3
我使用 Mico 和 Bernard 提供的代码来提供自己的答案。
我认为这种格式看起来不错,尤其是与 booktabs-threeparttable-layout 中的其他表格一起使用时。
附言:我不确定每个点的间距是否都很好。
\documentclass[preview, border={10pt 10pt -180pt 10pt}]{standalone}
\usepackage{booktabs}
\usepackage{threeparttable}
%% Define a few struts
%% (from code by Claudio Beccari in TeX and TUG News, Vol. 2, 1993)
\newcommand\Tstrut{\rule{0pt}{2.7ex}} % "top" strut
\begin{document}
\begin{table}[h!]
\begin{threeparttable}
\caption{Name}
\begin{tabular}{c|ccccccc}
\toprule
& B & C & D & E & F & G & H\\
\hline
A & 1 & 2 & 3 & 4 & 5 & 6 & 7\Tstrut\\
B & & 9 & 0 & 1 & 2 & 3 & 4\\
C & & & 5 & 6 & 7 & 8 & 9\\
D & & & & 0 & 1 & 2 & 3\\
E & & & & & 4 & 5 & 6\\
F & & & & & & 7 & 8\\
G & & & & & & & 9\\
\bottomrule
\end{tabular}
\begin{tablenotes}\footnotesize
\item[] A --- Apple, B --- Banana, C --- Cherry, D --- Date, E --- Elderberry, F --- Fig, G --- Grape, H --- Honeydew melon
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}