以下代码没有产生我期望的结果。当通过重新设置标题样式来更改标题位置时,它不再居中;而是向左移动。
关于如何修复该问题有什么想法吗(我不想移动里面的 threeparttable 标题)。
\documentclass{scrartcl}
\usepackage{array}
\usepackage{ragged2e}
\usepackage{booktabs}
\usepackage{threeparttable}
\usepackage{siunitx}
\usepackage{xparse}
\usepackage{float}
\floatstyle{komaabove}
\restylefloat{table}
\newcolumntype{L}[1]{>{\RaggedRight\hspace{0pt}}p{\dimexpr #1\linewidth-2\tabcolsep}}
\newcolumntype{C}[1]{>{\Centering\hspace{0pt}}p{\dimexpr #1\linewidth-2\tabcolsep}}
\newcommand{\uhrule}{\midrule[\heavyrulewidth]}
\DeclareExpandableDocumentCommand{\mcc}{o o m}{%
\IfNoValueTF{#1}
{\multicolumn{1}{c}{#3}}
{\IfNoValueTF{#2}
{\multicolumn{#1}{c}{#3}}
{\multicolumn{#1}{C{#2}}{#3}}
}
}
\begin{document}
\begin{table}[t]
\centering
\begin{threeparttable}
\begin{tabular}{L{0.15}
S[table-format=6]
S[table-format=5]
S[table-format=2.1,
table-space-text-post = {**}]
}
\toprule
Race
& \mcc[1][0.20]{Population\tnote{b}}
& \mcc[1][0.20]{Homicides}
& \mcc[1][0.10]{Rate\tnote{c}} \\ \uhrule
Black\tnote{d} & 29986 & 12114 & 40.5* \\
White & 199686 & 12153 & 6.1 \\
Other\tnote{e} & 19038 & 635 & 3.3** \\ \midrule
Total & 248710 & 24932 & 10.0 \\
\bottomrule
\end{tabular}
\begin{tablenotes}[flushleft]
\item[a] Data developped from the Statistical Abstract of the United States -- 1993.
\item[b] Population in $1000$s.
\item[c] Rate per $100\,000$ in the population.
\item[d] The rate for \emph{Black} males was 69.2, for \emph{White} males it was 9.0.
\item[e] About one-half of the \emph{Other} category was composed of Asian Americans and Native Americans.
\end{tablenotes}
$*p<.001$, two-tailed test. $**p<0.05$, two-tailed test.
\caption{Homicides by race of the victim in 1993 in the USA.\tnote{a}}
\label{tab5}
\end{threeparttable}
\end{table}
\end{document}
答案1
环境threeparttable
使用其内部的标题位置来决定排版。因此,尽管这可能不方便,但您需要将其放置在环境\caption
之前tabular
。
\documentclass{scrartcl}
\usepackage{array}
\usepackage{ragged2e}
\usepackage{booktabs}
\usepackage{threeparttable}
\usepackage{siunitx}
\usepackage{xparse}
\usepackage{float}
\floatstyle{komaabove}
\restylefloat{table}
\newcolumntype{L}[1]{>{\RaggedRight\hspace{0pt}}p{\dimexpr #1\linewidth-2\tabcolsep}}
\newcolumntype{C}[1]{>{\Centering\hspace{0pt}}p{\dimexpr #1\linewidth-2\tabcolsep}}
\newcommand{\uhrule}{\midrule[\heavyrulewidth]}
\DeclareExpandableDocumentCommand{\mcc}{o o m}{%
\IfNoValueTF{#1}
{\multicolumn{1}{c}{#3}}
{\IfNoValueTF{#2}
{\multicolumn{#1}{c}{#3}}
{\multicolumn{#1}{C{#2}}{#3}}
}
}
\begin{document}
\begin{table}[t]
\centering
\begin{threeparttable}
\caption{Homicides by race of the victim in 1993 in the USA.\tnote{a}}
\label{tab5}
\begin{tabular}{L{0.15}
S[table-format=6]
S[table-format=5]
S[table-format=2.1,
table-space-text-post = {**}]
}
\toprule
Race
& \mcc[1][0.20]{Population\tnote{b}}
& \mcc[1][0.20]{Homicides}
& \mcc[1][0.10]{Rate\tnote{c}} \\ \uhrule
Black\tnote{d} & 29986 & 12114 & 40.5* \\
White & 199686 & 12153 & 6.1 \\
Other\tnote{e} & 19038 & 635 & 3.3** \\ \midrule
Total & 248710 & 24932 & 10.0 \\
\bottomrule
\end{tabular}
\begin{tablenotes}[flushleft]
\item[a] Data developped from the Statistical Abstract of the United States -- 1993.
\item[b] Population in $1000$s.
\item[c] Rate per $100\,000$ in the population.
\item[d] The rate for \emph{Black} males was 69.2, for \emph{White} males it was 9.0.
\item[e] About one-half of the \emph{Other} category was composed of Asian Americans and Native Americans.
\end{tablenotes}
$*p<.001$, two-tailed test. $**p<0.05$, two-tailed test.
\end{threeparttable}
\end{table}
\end{document}