请看一下这张表:
1) 我不明白为什么该行\cmidrule(lr){2-3}
没有位于“广告”开头的正上方。
2)我不明白为什么 69% 与上面的 3 个值不一致。
有人可以帮我纠正这两点吗?
这是我的代码(我包含了完整的序言,以防由于包之间的冲突):
\documentclass[12pt]{article}
\usepackage{setspace,amsmath,graphicx,float}
\usepackage[english]{babel}
\usepackage[natbibapa]{apacite}
\usepackage{boldline}
\usepackage{array}
\usepackage{ragged2e}
\usepackage{url}
\usepackage{fancyhdr}
\usepackage{changepage}
\usepackage[left=3cm,top=3.5cm,right=2.5cm,bottom=2.5cm]{geometry}
\usepackage{newtxtext, newtxmath}
\usepackage{eurosym}
\usepackage{nameref}
\usepackage[nottoc]{tocbibind}
\usepackage[bottom]{footmisc}
\edef\restoreparindent{\parindent=\the\parindent\relax}
\usepackage{parskip}
\usepackage{enumitem}
\usepackage{tabularx}
\usepackage{threeparttable}
\usepackage{color}
\usepackage{tikz}
\usetikzlibrary{arrows, arrows.meta, calc, positioning, quotes, shapes, patterns}
\usepackage[margin=1cm]{caption}
\captionsetup[figure]{skip=18pt}
\usepackage[labelfont=bf]{caption}
\usepackage{etoolbox}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{amssymb}
\usepackage{nccmath}
\begin{document}
\begin{table}[h]
\caption[Gross profit ratio for Axel Springer and ProSiebenSat.1]{Gross profit ratio for Axel Springer and ProSiebenSat.1 per side.}
\centering
\begin{threeparttable}
\begin{tabular*}{\textwidth}{l@{\extracolsep{\fill}} c c c c}
\toprule
& \multicolumn{2}{c}{Axel Springer} & \multicolumn{2}{c}{ProSiebenSat.1} \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5}
& Advertisement & Circulation & Advertisement & Viewers \\
\midrule
Revenue (A) & 1,089 & 1,313 & 1834 & 0 \\[1ex]
Variable costs (B) & 338 & 407 & 1265 & 0 \\[1ex]
Gross profit (A - B) & 751 & 906 & 569 & 0 \\[1ex]
Gross profit ratio (A - B) / A & 69\% & 69\% & 31\% & - \\
\bottomrule
\end{tabular*}
\begin{tablenotes}
\raggedright
\item \textit{Note}: Adapted from Axel Springer and ProSiebenSat.1's income statement in 2004. All numbers in million Euro.
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
答案1
你放错了\extracolsep{\fill}
:
\documentclass[12pt]{article}
\usepackage[left=3cm,top=3.5cm,right=2.5cm,bottom=2.5cm]{geometry}
\usepackage{newtxtext, newtxmath}
\usepackage{threeparttable}
\usepackage{booktabs}
\begin{document}
\begin{table}[h]
\caption[Gross profit ratio for Axel Springer and ProSiebenSat.1]
{Gross profit ratio for Axel Springer and ProSiebenSat.1 per side.}
\begin{threeparttable}
\begin{tabular*}{\textwidth}{
@{\extracolsep{\fill}\hspace{\tabcolsep}}
l
c
c
c
c
@{\hspace{\tabcolsep}}
}
\toprule
& \multicolumn{2}{c}{Axel Springer} & \multicolumn{2}{c}{ProSiebenSat.1} \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5}
& Advertisement & Circulation & Advertisement & Viewers \\
\midrule
Revenue (A) & 1,089 & 1,313 & 1834 & 0 \\
\addlinespace
Variable costs (B) & 338 & 407 & 1265 & 0 \\
\addlinespace
Gross profit (A - B) & 751 & 906 & 569 & 0 \\
\addlinespace
Gross profit ratio (A - B) / A & 69\% & 69\% & 31\% & -- \\
\bottomrule
\end{tabular*}
\begin{tablenotes}
\raggedright
\item \textit{Note}: Adapted from Axel Springer and ProSiebenSat.1's income statement
in 2004. All numbers in million Euro.
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
(我将连字符改为短破折号。)
我可能应该省略左侧和右侧的填充。以下是仅适用于的代码tabular
;并不是说第二个\cmidrule
应该只在左侧修剪,并且第二个\multicolumn
应该有c@{}
。
\begin{tabular*}{\textwidth}{
@{\extracolsep{\fill}}
l
c
c
c
c
@{}
}
\toprule
& \multicolumn{2}{c}{Axel Springer} & \multicolumn{2}{c@{}}{ProSiebenSat.1} \\
\cmidrule(lr){2-3} \cmidrule(l){4-5}
& Advertisement & Circulation & Advertisement & Viewers \\
\midrule
Revenue (A) & 1,089 & 1,313 & 1834 & 0 \\
\addlinespace
Variable costs (B) & 338 & 407 & 1265 & 0 \\
\addlinespace
Gross profit (A - B) & 751 & 906 & 569 & 0 \\
\addlinespace
Gross profit ratio (A - B) / A & 69\% & 69\% & 31\% & -- \\
\bottomrule
\end{tabular*}
答案2
当使用tabular*
环境和@{\extracolsep{\fill}}
语句时,我几乎总是发现最好将长度变量设置\tabcolsep
为0pt
。这样,LaTeX 就可以最大限度地自由地找到最佳的列间空白量。这种方法的一个非常好的副作用是,不需要对通过 绘制的线条进行任何左侧和/或右侧修剪\cmidrule
。
另一条评论:为了提高表格内容的可读性,将数字与其(隐式)小数点对齐而不是居中会很有用。此观察适用于下面显示的代码的前三个数据列。
\documentclass[12pt]{article}
%% I've omitted all preamble instructions that aren't relevant for the example at hand.
\usepackage[left=3cm,top=3.5cm,right=2.5cm,bottom=2.5cm]{geometry}
\usepackage{newtxtext,newtxmath}
\usepackage[margin=1cm,labelfont=bf]{caption}
\captionsetup[figure]{skip=18pt}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{table}[h!]
\sisetup{table-format=4.0,group-minimum-digits=4,group-separator={,}} % <-- new
\setlength\tabcolsep{0pt} % <-- new
\caption[Gross profit ratio for Axel Springer and ProSiebenSat.1]{%
Gross profit ratio for Axel Springer and ProSiebenSat.1 per side.}
%\centering %% redundant
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} lSSSc}
\toprule
& \multicolumn{2}{c}{Axel Springer} & \multicolumn{2}{c}{ProSiebenSat.1} \\
\cmidrule{2-3} \cmidrule{4-5} % no trimming necessary
& {Advertisement} & {Circulation} & {Advertisement} & Viewers \\
\midrule
Revenue $(A)$ & 1089 & 1313 & 1834 & 0 \\[1ex]
Variable costs $(B)$ & 338 & 407 & 1265 & 0 \\[1ex]
Gross profit $(A - B)$ & 751 & 906 & 569 & 0 \\[1ex]
Gross profit ratio $(A-B)/A$ &{69\%}&{69\%}&{31\%}& {--}\\
\bottomrule
\end{tabular*}
\medskip\raggedright\footnotesize
\textit{Note}: Adapted from Axel Springer and ProSiebenSat.1's
income statement in 2004. All numbers in million euro.
\end{table}
\end{document}