3

Simon Dispa's excellent answer to my last question went a long way in replicating the para, flushleft variant of threeparttable's table notes. But the formatting in threeparttable (after some adjustments) in my opinion generally looks nicer as it does a better job honoring the right margin.

Is there some way to replicate this behavior with tabularray? Or at least improve on its behavior in the example below?

\documentclass{article}
\usepackage{tabularx,booktabs}
\usepackage[para, flushleft]{threeparttable}
\makeatletter
\def\TPT@doparanotes{\par% Alter threeparttable's excessive linebreaks before new notes: https://tex.stackexchange.com/a/564293/71332
   \prevdepth\z@ \TPT@hsize
   \TPTnoteSettings
   \parindent\z@ \pretolerance 8
   \linepenalty 200
   \renewcommand\item[1][]{\relax\ifhmode \begingroup
       \unskip
       \penalty -45 \hskip\z@\@plus 10pt\penalty-19
       \hskip 25pt \penalty 9999 \hskip-25pt
       \hskip 1em\@plus3pt
      \endgroup\fi
      \tnote{##1}\,\ignorespaces}%
   \let\TPToverlap\relax
   \def\endtablenotes{\par}%
}
\makeatother

\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\SetTblrStyle{note-tag}{font=\rmfamily}

% Simon Dispa's emulation of threeparttable: https://tex.stackexchange.com/a/616081/71332
\DefTblrTemplate{remark-sep}{three}{:\space}
\DefTblrTemplate{note-sep}{three}{\,}

\DefTblrTemplate{remark}{inline-noclosingpar}{% similar to the remark plain
\MapTblrRemarks{%
  \noindent%
  \UseTblrTemplate{remark-tag}{default}%
  \UseTblrTemplate{remark-sep}{three}%
  \UseTblrTemplate{remark-text}{default}%
  \space\space}
}

\DefTblrTemplate{note}{inline-three}{%
  \MapTblrNotes{%
    \noindent%
    \UseTblrTemplate{note-tag}{default}%
    \UseTblrTemplate{note-sep}{three}%
    \UseTblrTemplate{note-text}{default}%
    \space%
  }
}

\DefTblrTemplate{lastfoot}{mytemplate}{%
  \UseTblrTemplate{remark}{inline-noclosingpar}%
  \UseTblrTemplate{note}{inline-three}%
}

\NewTblrTheme{mytheme}{%
  \SetTblrTemplate{lastfoot}{mytemplate}%
}

\begin{document}
  \begin{table}
    \begin{threeparttable}
      \caption{A \texttt{threeparttable} table with adjusted \texttt{tablenotes}}
      \begin{tabularx}{\linewidth}{@{}Xcc@{}}
        \toprule
        & A & B \\
        \midrule
        A row heading\tnote{a} & a & 123 \\
        Another row heading\tnote{b} & b & 456 \\
        Yet another row heading & c & 789 \\
        \bottomrule
      \end{tabularx}
      \begin{tablenotes}
        \emph{Note}: A few words describing something noteworthy.
        \emph{Source}: Made up by me.
        \item[a] A table footnote that goes on for a few words more than this.
        \item[b] Another table footnote that goes on for a few words more than this.
      \end{tablenotes}
    \end{threeparttable}
  \end{table}

  \begin{table}
    \begin{booktabs}[
      tall,
      theme=mytheme,
      caption={A \texttt{tabularray} table emulating a \texttt{threeparttable}},
      remark{Note}={A few words describing something noteworthy.},
      remark{Source}={Made up by me.},
      note{a}={A table footnote that goes on for a few words more than this.},
      note{b}={Another table footnote that goes on for a few words more than this.}
    ]{
      colspec={@{}Xcc@{}},
      width=\linewidth
    }
      \toprule
      & A & B \\
      \midrule
      A row heading\TblrNote{a} & a & 123 \\
      Another row heading\TblrNote{b} & b & 456 \\
      Yet another row heading & c & 789 \\
      \bottomrule
    \end{booktabs}
  \end{table}
\end{document}

Screenshot

1
  • 1
    Thank you for your feedback!. Now it is downhill. Commented Sep 22, 2021 at 13:32

1 Answer 1

5

The space between notes in threeparttable seems excessive, so I (also) changed it.

a

\documentclass{article}
\usepackage{tabularx,booktabs}
\usepackage[para, flushleft]{threeparttable}
\makeatletter
\def\TPT@doparanotes{\par% Alter threeparttable's excessive linebreaks before new notes: https://tex.stackexchange.com/a/564293/71332
    \prevdepth\z@ \TPT@hsize
    \TPTnoteSettings
    \parindent\z@ \pretolerance 8
    \linepenalty 200
    \renewcommand\item[1][]{\relax\ifhmode \begingroup
        \unskip
        \penalty -45 \hskip\z@\@plus 10pt\penalty-19
        \hskip 25pt \penalty 9999 \hskip-25pt
        \hskip 1ex\@plus3pt % corrected  1ex instead of 1em <<<<<<<<<<
        \endgroup\fi
        \tnote{##1}\,\ignorespaces}%
    \let\TPToverlap\relax
    \def\endtablenotes{\par}%
}
\makeatother

\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\SetTblrStyle{note-tag}{font=\rmfamily}

% Simon Dispa's emulation of threeparttable: https://tex.stackexchange.com/a/616081/71332
\DefTblrTemplate{remark-sep}{three}{:\space}
\DefTblrTemplate{note-sep}{three}{\,}

\DefTblrTemplate{remark-text}{three}{\InsertTblrRemarkText\!}% added <<<<<<<<<<<
\DefTblrTemplate {note-text}{three}{\InsertTblrNoteText\!}% added <<<<<

\DefTblrTemplate{remark}{inline-noclosingpar}{% similar to the remark plain
    \MapTblrRemarks{%
        \noindent%
        \UseTblrTemplate{remark-tag}{default}%
        \UseTblrTemplate{remark-sep}{three}%
        \UseTblrTemplate{remark-text}{three}%
        \space\space}
}

\DefTblrTemplate{note}{inline-three}{%
    \MapTblrNotes{%
        \noindent%
        \UseTblrTemplate{note-tag}{default}%
        \UseTblrTemplate{note-sep}{three}%
        \UseTblrTemplate{note-text}{three}%
        \space%
    }
}

\DefTblrTemplate{lastfoot}{mytemplate}{%
    \UseTblrTemplate{remark}{inline-noclosingpar}%
    \UseTblrTemplate{note}{inline-three}%
}

\NewTblrTheme{mytheme}{%
    \SetTblrTemplate{lastfoot}{mytemplate}%
}

\begin{document}
    \begin{table}
        \begin{threeparttable}
            \caption{A \texttt{threeparttable} table with adjusted \texttt{tablenotes}}
            \begin{tabularx}{\linewidth}{@{}Xcc@{}}
                \toprule
                & A & B \\
                \midrule
                A row heading\tnote{a} & a & 123 \\
                Another row heading\tnote{b} & b & 456 \\
                Yet another row heading & c & 789 \\
                \bottomrule
            \end{tabularx}
            \begin{tablenotes}
                \emph{Note}: A few words describing something noteworthy.
                \emph{Source}: Made up by me.
                \item[a] A table footnote that goes on for a few words more than this.
                \item[b] Another table footnote that goes on for a few words more than this.
            \end{tablenotes}
        \end{threeparttable}
    \end{table}
    
    \begin{table}
        \begin{booktabs}[
            tall,
            theme=mytheme,
            caption={A \texttt{tabularray} table emulating a \texttt{threeparttable}},
            remark{Note}={A few words describing something noteworthy.},
            remark{Source}={Made up by me.},
            note{a}={A table footnote that goes on for a few words more than this.},
            note{b}={Another table footnote that goes on for a few words more than this.}
            ]{
                colspec={@{}Xcc@{}},
                width=\linewidth
            }
            \toprule
            & A & B \\
            \midrule
            A row heading\TblrNote{a} & a & 123 \\
            Another row heading\TblrNote{b} & b & 456 \\
            Yet another row heading & c & 789 \\
            \bottomrule
        \end{booktabs}
    \end{table}
    \hfill
\end{document}

You must log in to answer this question.

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