2

The following code does not produce the result I would expect. When the caption position is changed by restyling the caption it is no longer centred; it moves to the left.

Any idea on how to fix the problem (I don't want to move the inside threeparttable caption).

\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}
2
  • When I run your code, the table is still centered, but the caption moves to the left.Do you get a different result? Jun 30, 2013 at 3:19
  • @Gonzalo Medina Yes, the problem is the caption moving to the left. I have corrected the post.
    – Pierre
    Jun 30, 2013 at 12:05

1 Answer 1

1

The threeparttable environment uses the caption placement inside it for deciding the typesetting. So, although this might be inconvenient, you need to place \caption before the tabular environment.

\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}

enter image description here

4
  • I had found out that you could do it this way, although the formatting is not quite the same as when placing caption at the bottom of the table; more precisely the caption does not fit the width of the table when at the top. Mind you I am not sure it's a problem!
    – Pierre
    Jun 30, 2013 at 23:47
  • I found out that if you remove the lines \floatstyle{komaabove} and \restylefloat{table} then the caption formatting is correct.
    – Pierre
    Jul 1, 2013 at 0:46
  • @Pierre Fitting the caption to the size of the table is surely one of the bad things about threeparttable.
    – egreg
    Jul 1, 2013 at 8:37
  • Yes you are right. This is indeed problematic with small tables. Table notes would be as well. You can renew \TPTminimum, but then this would not look good with centering. Maybe centering is simply not the right thing to do with tables.
    – Pierre
    Jul 1, 2013 at 14:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .