目标:
- 在包含表 1 的列标题的文本行上方和下方添加空格。
- 在第二条 hline 下方添加一个空格。
- 在第三条水平线上方添加一个空格。
下面的代码包含原始表(#1)以及为实现上述目标而进行的几次失败的尝试(#2、#3、#4)。
额外细节:
我正在使用
pdflatex
渲染.tex
文件我正在使用这个
tabularx
包。我正在使用
xtable()
R 来构建.tex
这些表,但没有必要用选项来回答问题,因为我可以在使用 R 后xtable
编辑。.tex
任何帮助都将不胜感激。有什么建议吗?
%%%%%%%%%%
\documentclass{article}
\usepackage{graphicx}
\usepackage[sc]{mathpazo}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage[labelfont=sf,hypcap=false,format=hang,width=1\columnwidth]{caption}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=3cm,rmargin=3cm}
\usepackage{longtable}
\usepackage{tabularx}
\usepackage{array}
\begin{document}
%%%%%%%%%%
\title{Understanding Tables: Vertical Spacing}
\author{Brian}
\maketitle
This report is designed to be a quick resource for editing the vertical spacing in 'tabularx' tables. \\
\begin{table}[ht]
\captionof{table}{Original}
\centering
\begin{tabular}{lrrrrrr}
\hline
Type & Total & Mean & Median & Stdev & Min & Max \\
\hline
Test1 & 490 & 15 & 8 & 24 & 1 & 115 \\
Test2 & 52610 & 1697 & 1620 & 430 & 920 & 2850 \\
\hline
\end{tabular}
\end{table}
{\renewcommand{\arraystretch}{2}%
\begin{table}[ht]
\captionof{table}{Spaceing stretched above and below ALL cells}
\centering
\begin{tabular}{lrrrrrr}
\hline
Type & Total & Mean & Median & Stdev & Min & Max \\
\hline
Test1 & 490 & 15 & 8 & 24 & 1 & 115 \\
Test2 & 52610 & 1697 & 1620 & 430 & 920 & 2850 \\
\hline
\end{tabular}
\end{table}}
\begin{table}[ht]
\captionof{table}{Spacing streched ABOVE header}
\centering
\begin{tabular}{lrrrrrr}
\hline
\rule{0pt}{4ex}Type & Total & Mean & Median & Stdev & Min & Max \\
\hline
Test1 & 490 & 15 & 8 & 24 & 1 & 115 \\
Test2 & 52610 & 1697 & 1620 & 430 & 920 & 2850 \\
\hline
\end{tabular}
\end{table}
\begin{table}[ht]
\captionof{table}{Spacing streched ABOVE ALL cells}
\centering
\setlength\extrarowheight{14pt}
\begin{tabular}{lrrrrrr}
\hline
Type & Total & Mean & Median & Stdev & Min & Max \\
\hline
Test1 & 490 & 15 & 8 & 24 & 1 & 115 \\
Test2 & 52610 & 1697 & 1620 & 430 & 920 & 2850 \\
\hline
\end{tabular}
\end{table}
\end{document}
答案1
您在此处的方法(就水平规则而言)与以下方法相符:booktabs
。以下是我将使用的内容:
\documentclass{article}
\usepackage[sc]{mathpazo}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage[labelfont=sf,hypcap=false,format=hang,width=\columnwidth]{caption}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=3cm,rmargin=3cm}
\usepackage{tabularx,booktabs}
\begin{document}
\begin{table}[ht]
\caption{Original}
\centering
\begin{tabular}{lrrrrrr}
\hline
Type & Total & Mean & Median & Stdev & Min & Max \\
\hline
Test1 & 490 & 15 & 8 & 24 & 1 & 115 \\
Test2 & 52610 & 1697 & 1620 & 430 & 920 & 2850 \\
\hline
\end{tabular}
\end{table}
\begin{table}[ht]
\renewcommand{\arraystretch}{1.2}%
\caption{\texttt{booktabs} version}
\centering
\begin{tabular}{l *{6}{r} }
\toprule
Type & Total & Mean & Median & Stdev & Min & Max \\
\midrule
Test1 & 490 & 15 & 8 & 24 & 1 & 115 \\
Test2 & 52610 & 1697 & 1620 & 430 & 920 & 2850 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
booktabs
' \toprule
,\midrule
并\bottomrule
插入额外的(白色)线,以便稍微分隔这些线周围的文本。这与使用增加的线\arraystretch
似乎足以获得透气效果。
答案2
您可以尝试cellspace
定义最小带有以字母 为前缀的说明符的列中单元格上方和下方的垂直间距S
。如果使用siunitx
也使用字母的包S
,则前缀将替换为字母C
:
%%%%%%%%%%
\documentclass{article}
\usepackage{graphicx}
\usepackage[sc]{mathpazo}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage[labelfont=sf,hypcap=false,format=hang,width=1\columnwidth]{caption}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=3cm,rmargin=3cm}
\usepackage{longtable}
\usepackage{tabularx}
\usepackage{array, booktabs}
\usepackage{siunitx}
\sisetup{table-format =4.0,table-number-alignment = center}
\usepackage{cellspace}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
\begin{document}
%%%%%%%%%%
\title{Understanding Tables: Vertical Spacing}
\author{Brian}
\maketitle
This report is designed to be a quick resource for editing the vertical spacing in 'tabularx' tables. \\
\begin{table}[ht]
\captionof{table}{With \texttt{cellspace}}
\centering
\begin{tabular}{ClS[table-format=5.0]SSS[table-format=3.0]S[table-format=3.0] S}
\toprule
Type & {Total} & {Mean} & {Median} & {Stdev} & {Min} & {Max} \\
\midrule
Test1 & 490 & 15 & 8 & 24 & 1 & 115 \\
Test2 & 52610 & 1697 & 1620 & 430 & 920 & 2850 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}