2

I am trying to use an earlier solution posted here which combines the tabu and threeparttable to stretch table columns according to \textwidth. However, as soon as I change the article class to apa6 the earlier solution produces errors.

\documentclass[a4paper,floatsintext,man,donotrepeattitle]{apa6}
\usepackage{booktabs}
\usepackage{threeparttable,tabu}

\usepackage{xpatch}
\makeatletter
\chardef\TPT@@@asteriskcatcode=\catcode`*
\catcode`*=11
\xpatchcmd{\threeparttable}
{\TPT@hookin{tabular}}
{\TPT@hookin{tabular}\TPT@hookin{tabu}}
{}{}
\catcode`*=\TPT@@@asteriskcatcode
\makeatother

\begin{document}
\centering
\begin{threeparttable}
    \begin{tabu} to .4\textwidth {XX}
        a & b   \\\toprule
        0 & 1   \\\bottomrule
    \end{tabu}
    \begin{tablenotes}
        \footnotesize
        \item[*] This is a long table note text, long enough to exceed the table's width.
    \end{tablenotes}
\end{threeparttable}

\end{document}

The errors are:

Extra }, or forgotten \endgroup. \end{tabu}
Undefined control sequence. \end{document}

My question: How to stretch a tables with apa6 when also including tablenotes? That is, I am not bound to the tabu or threeparttable class, but it seems easiest to me.


As tabularx was suggested as an alternative, it also produces a compilation error when used together with threeparttable and apa6 (but again not when using only the article class).

\documentclass[a4paper,floatsintext,man,donotrepeattitle]{apa6}
%\documentclass{article}
\usepackage{booktabs}
\usepackage{tabularx,threeparttable}

\begin{document}

\begin{threeparttable}
    \begin{tabularx}{\textwidth} {XX}
        \toprule
        a & b   \\\midrule
        0 & 1   \\\bottomrule
    \end{tabularx}
    \begin{tablenotes}
        \footnotesize
        \item[*] This is a long table note text, long enough to exceed the table's width.
    \end{tablenotes}
\end{threeparttable}

\end{document}

produces:

Undefined control sequence. \end{document}
Underfull \hbox (badness 10000) in alignment
Henrik
  • 865
  • 1
    Do you have any particular reason for using tabu instead of tabularx? By the way, there's no reason for either, if you just want two columns whose widths sum up to .4\textwidth. – egreg Feb 06 '17 at 15:24
  • No. Just from reading other answers here tabu seemed to be the correct choice. I have no preference whatsoever (other than using the apa6class). – Henrik Feb 06 '17 at 15:25
  • 2
    In my opinion, tabu is almost never the correct choice; I might be biased. – egreg Feb 06 '17 at 15:27
  • @egreg I have found no way to proportionally expand a table with several columns to \textwidth (or some proportion of it) without additional packages. I am happy to be proven otherwise. And also happy for solutions involving tabularx. – Henrik Feb 06 '17 at 15:28
  • \begin{tabular}{p{\dimexpr.2\textwidth-2\tabcolsep}p{\dimexpr.2\textwidth-2\tabcolsep}} would do. – egreg Feb 06 '17 at 15:39
  • @egreg The problem with such an approach is that the example is obviously just a toy example. In my real examples the columns have different widths (which I do not know) and need to scale them proportionally to the actual width. Hence, I would appreciate an example in which I do not need to specify the actual widths, but let a package do that. – Henrik Feb 06 '17 at 15:42
  • if you will add to preamble \shorttitle{Some title}, your second example will work as expected. – Zarko Feb 09 '17 at 11:00
  • @Zarko Damn, that was an easy fix and a stupid mistake. If you post this as a complete answer the bounty is yours. – Henrik Feb 09 '17 at 13:20
  • @Henrik, done :) – Zarko Feb 09 '17 at 13:34

1 Answers1

2

Using ˙apa6 require to use \shorttitle{Some title} in preamble. If you not need it, than it is suffice to add \shorttitle{}:

\documentclass[a4paper,floatsintext,man,donotrepeattitle]{apa6}
\usepackage{booktabs,tabularx,threeparttable}
\shorttitle{}% short title, can be empty but not deleted

\usepackage{lipsum}% only for test purpose

\begin{document}
\lipsum[1]

\begin{center}
\begin{threeparttable}
    \begin{tabularx}{.4\textwidth}{XX}
                    \toprule
        a & b   \\  \midrule
        0 & 1   \\  \bottomrule
    \end{tabularx}
    \begin{tablenotes}
        \footnotesize
        \item[*] This is a long table note text, long enough to exceed the table's width.
    \end{tablenotes}
\end{center}
\end{threeparttable}

\end{document}

enter image description here

Zarko
  • 296,517