4

Why is the tnote of my threeparttable's table cheekily protruding? How can the width be (automatically) adjusted here?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tabulary}
\usepackage{threeparttable}
\usepackage{array}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{lipsum}
\renewcommand{\arraystretch}{1.2}
\sisetup{round-mode=places,round-precision=1, add-decimal-zero=true, add-integer-zero=true, round-integer-to-decimal}

\begin{document}



\lipsum[1]



\begin{table}
\centering
\begin{threeparttable}
\caption{Some long boring caption don't fall asleep 2013}

\begin{tabulary}{\textwidth}{@{}*{1}{l}*{2}{S[table-format=3.2]}@{}}
\toprule
& {incl.\ Ingredients A\tnote{1a}} & {excl.\ Ingredients A\tnote{1b}} \\
\midrule
DDDDDDDDDDD & 36.1 & 22.0\\
GGGGGGGGGGGG & 30.9 & 20.0\\
GGGG\tnote{2} & 33.0 & 22.8\\
OOOO\tnote{2} & 33.766 & 24.643
\\ \bottomrule
\end{tabulary}

\begin{tablenotes}
\item [2] Unweighted Average
\item [] Source: radiowaves from outer space 1999
\end{tablenotes}

\end{threeparttable}
\end{table}



\lipsum[2]



\end{document}
  • You don't have "extendable" columns: use J instead of *{1}{l} (or L if you want ragged right text in case it has to be split across lines). – egreg Apr 14 '13 at 8:58
  • @egreg \begin{tabulary}{\textwidth}{@{}L*{2}{S[table-format=3.2]}@{}} \toprule (or J instead of L) doesn't seem to do the trick, yet. Is there a difference between *{1}{L} and simply L ? – nutty about natty Apr 14 '13 at 9:07
  • *{1}{L} is just a complicated way to say L. The argument of \tnote is typeset without taking up space, which is usually what's wanted when the note is in the body of the table (but not in the "description" parts such as headers, it seems). – egreg Apr 14 '13 at 9:10
  • @egreg hmm, so the "extendable" column don't take the \tnotes into account... what to do about it? – nutty about natty Apr 14 '13 at 9:15
  • @egreg Are you sure about the body_vs_header bit? Cuz somewhere on SX I read that for "tnotes" in the middle of the body should be typeset as \newcommand{\mtnote}[1]{\textsuperscript{\TPTtagStyle{#1}}} an \mnote (that is, these should be used if the note is not at the end of the line and the line has more text coming after the note). – nutty about natty Apr 14 '13 at 9:23
4

\tnote typesets its argument in a zero width box, so it won't influence the typesetting of the data. This might be not wanted in headers or descriptions; you can add a command that mimicks the work of \tnote but uses the full width.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tabulary}
\usepackage{threeparttable}
\usepackage{array}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{lipsum}
\renewcommand{\arraystretch}{1.2}
\sisetup{round-mode=places,
 round-precision=1,
 add-decimal-zero=true,
 add-integer-zero=true,
 round-integer-to-decimal}

% This is like `\tnote`, but uses the space of the argument    
\newcommand\stnote[1]{\textsuperscript{\TPTtagStyle{#1}}}

\begin{document}

\lipsum[1]

\begin{table}[ht]
\centering
\begin{threeparttable}
\caption{Some long boring caption don't fall asleep 2013}

\begin{tabulary}{\textwidth}{@{} L *{2}{S[table-format=3.2]}@{}}
\toprule
& {incl.\ Ingredients A\stnote{1a}} & {excl.\ Ingredients A\stnote{1b}} \\
\midrule
DDDDDDDDDDD   & 36.1   & 22.0   \\
GGGGGGGGGGGG  & 30.9   & 20.0   \\
GGGG\tnote{2} & 33.0   & 22.8   \\
OOOO\tnote{2} & 33.766 & 24.643 \\
\bottomrule
\end{tabulary}

\begin{tablenotes}
\item [2] Unweighted Average
\item [] Source: radiowaves from outer space 1999
\end{tablenotes}

\end{threeparttable}
\end{table}

\lipsum[2]

\end{document}

enter image description here

Note that in order to do something sensible with tabulary you have to add at least an "undetermined width column", specified with one character from LCRJ each one denoting the desired alignment in the column cells: left alignment (ragged right), centering, right alignment (ragged left), justified.


A slightly different definition that allows using \stnote in the caption without it appearing in the list of tables: change the definition of \stnote with

\usepackage{etoolbox}
\makeatletter
\apptocmd{\TPT@begintabbox}{\let\mTPTprint\@firstofone}{}{}
\apptocmd{\threeparttable}{\let\mTPTprint\relax}{}{}
\newcommand\stnote[1]{\protect\mTPTprint{\textsuperscript{\TPTtagStyle{#1}}}}
\newcommand\mTPTprint[1]{}
\makeatother
  • about tabulary and LCRJ: I was using L by default (only in the MWE above did the l somehow slip in ;) – nutty about natty Apr 14 '13 at 9:25
  • ok... so it's just like the \mnote (see my comment @ my question above) which I'd already been using for "middle-notes"... see your answer to this question: tex.stackexchange.com/a/56686/27721 – nutty about natty Apr 14 '13 at 9:27
  • I just found out the the \mtnote will appear in the list of tables, unlike the "original" \tnote (cf threeparttable manual). How could I make sure that also the \mtnote does not appear in the LoT ? – nutty about natty Apr 16 '13 at 5:26
  • ps: \mtnote (or \stnote) will (unlike \tnote) appear in the LoT only if it's being used in the \caption of the threeparttable... – nutty about natty Apr 16 '13 at 5:59
  • 1
    @nuttyaboutnatty If you put that code in a class file, then \makeatletter and \makeatother mustn't be used. – egreg Apr 16 '13 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.