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}
ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
  • 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 08: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 09: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 09: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 09: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 09:23

1 Answers1

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
David Carlisle
  • 757,742
egreg
  • 1,121,712
  • 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 09: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: http://tex.stackexchange.com/a/56686/27721 – nutty about natty Apr 14 '13 at 09: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 05: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 05:59
  • @nuttyaboutnatty I don't understand what you mean. Can you add an example? – egreg Apr 16 '13 at 08:27
  • \begin{threeparttable} \caption{This is my long\mtnote{1} and complicated caption\tnote{1}} -- In \listoftables the 1 is dropped only for the original \tnote, not for your tweaked note. – nutty about natty Apr 16 '13 at 08:32
  • I'm using the microtype-pkg and this line in my preamble: \g@addto@macro\@verbatim{\microtypesetup{activate=false}}, "somewhere" after your code. Unfortunately, this returns an Undefined control sequence. l.84 \g \g@addto@macro\@verbatim{\microtypesetup{activate=false}} (prior to adding your new code there was no error (with microtype or otherwise). To me this is all (mostly) ancient Greek and I trust you blindfoldedly :) What can I do about it? – nutty about natty Apr 16 '13 at 10:29
  • @nuttyaboutnatty You probably have a \makeatletter before the added code. You're supposed to know what you're doing if using it. :) – egreg Apr 16 '13 at 11:10
  • hmm, can't find a another instance of \makeatletter. Most \usepackages I put into my *.cls file (cuz otherwise it didn't seem to work); I also put your code there; here I see a mention that that might be a bad idea. Between which sections of code would your code be most happy? – nutty about natty Apr 16 '13 at 11:23
  • 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