1

as background see my answer on this question.

i wonder, if it is possible that tablenotes be (automatically) split between pages on the way, that on each pages are present only items which are used on this pages. for given example example that on the first page tablenotes contain only items from 1 to 7 and on second package only items 1, 8 and 12.

for start i would be happy if it is possible to define two tablenotes and use the first one on the first table page and the second on the second page containing longtable.

1 Answer 1

1

This is the easy solution with many TableNotes.

Here I rewrote the TableNotes environment and \insertTableNotes to take an additional mandatory argument to name the table notes. Caution, there is no check, if a table note with a specific name (already) exists.

You can have as many table notes as you want (see second page of example). But of course there are only two feet for a longtable, so you can only have two differnt sets of notes. (If I could figure out, how to change a foot mid table, then there may be a chance to automate the notes. But so far, no luck.)

The result:

enter image description here

The code:

\documentclass[11pt, oneside]{book}
\usepackage[a4paper,
            hmargin={2.5cm},
            top=2.5cm,
            bottom=3.5cm]{geometry}
\usepackage{caption}
\usepackage[table]{xcolor}
\usepackage{array, ltablex, threeparttablex}
    \newcolumntype{C}{>{\centering\arraybackslash}X}
    \setlength\extrarowheight{3pt}

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\makeatletter
% rewritten macros from threeparttablex
\renewenvironment{TableNotes}[2][]{%
  \expandafter\gdef\csname TPTL@optarg@#2\endcsname{#1}%
  \expandafter\def\csname TPTL@collector@#2\endcsname##1{%
      \expandafter\long\expandafter\gdef\csname TPTL@body@#2\endcsname{##1}}%
  \expandafter\gdef\csname TPTL@body@#2\endcsname{}%
  \expandafter\Collect@Body\csname TPTL@collector@#2\endcsname}{}
% original code
%%%%\newenvironment{TableNotes}[1][]{
%%%%  \gdef\TPTL@optarg{#1}%
%%%%  \Collect@Body\TPTL@collector}{}
%%%%\newcommand\TPTL@collector[1]{%
%%%%  \long\gdef\TPTL@body{#1}}
%%%%% the macro used to store the tablenotes contents
%%%%\gdef\TPTL@body{}
% rewritten macros from threeparttablex
% added argument
\renewcommand\insertTableNotes[1]{%
  % first we need to know the width of the longtable, remember that it
  % will only settle after a few compilations
  \noalign{\begingroup
  \setlength\TPTL@width{0pt}
  \renewcommand\LT@entry[2]{\global\advance\TPTL@width by ##2}
  \@nameuse{LT@\romannumeral\c@LT@tables}
  \ifdim\TPTL@width<\TPTminimum\relax\global\TPTL@width=\TPTminimum\fi
  \endgroup}
  % then add the table notes inside a \parbox of the required width
  \multicolumn{\LT@cols}{c}{%
    \makebox[0pt][c]{%
      \parbox{\TPTL@width}{%
        \let\TPT@hsize\@empty% otherwise the width is not reset
                             % correctly as \TPT@hsize messes with 
                             % \@parboxrestore
        \let\TPToverlap\relax%
        % added
        \expandafter\let\expandafter\TPTL@optarg\csname TPTL@optarg@#1\endcsname
        \begin{tablenotes}[\TPTL@optarg]%
          \TPTL@font%
          % changed
          \csname TPTL@body@#1\endcsname
          % original
          %%%%\TPTL@body
        \end{tablenotes}
      }%
    }%
  }%
}
\makeatother

\begin{document}

\begin{ThreePartTable}
    \begin{TableNotes}[flushleft]{1}\footnotesize
\item \textbf{Table Notes:}
\item[1] textetxt.
\item[2] textetxt.
\item[3] textetxttextetxttextetxttextetxttextetxttextetx ttextetxt textetxt textetxttextetxttex tetxttextetxttextetxttextetxt textetxttextetxt textetxt.
\item[4] textetxt.
\item[5] textetxt.
\item[6] textetxt.
\item[7] textetxt.
\item[8] textetxt.
\item[9] textetxt.
\item[10] textetxt.
\item[11] textetxt.
\item[12] textetxt.
    \end{TableNotes}
    \begin{TableNotes}[flushleft]{2}\footnotesize
\item \textbf{Table Notes:}
\item[1] textetxt.
\item[8] textetxt.
\item[12] textetxt.
    \end{TableNotes}
    \begin{TableNotes}[flushleft]{3}\footnotesize
\item \textbf{Additional Notes:}
\item foo
\item bar
\item baz
    \end{TableNotes}
%
    \begin{tabularx}{\textwidth}{| X || c | C | c | }
\caption{holder holder holder holder holder holder holder holder holder holder holder holder holder holder holder holder.}
\label{ProCons_CSM_DTM_SSM}                                                 \\
    \hline
                &   \multicolumn{3}{c|}{\textbf{Hooooolder}}                \\
    \cline{2-4}
\textbf{holder} &   holder  &   holder  &   holder                          \\
    \hline\hline
\endfirsthead
    \hline
                &   \multicolumn{3}{c|}{\textbf{Hooooolder}}                \\
    \cline{2-4}
\textbf{holder} &   holder  &   holder  &   holder                          \\
    \hline\hline
\endhead
    \hline
\insertTableNotes{1}\medskip\\
    \hline
\multicolumn{4}{r}{\textit{Continue on the next page}}                     \\
\endfoot
    \hline
\insertTableNotes{2}\medskip\\
    \hline
\insertTableNotes{3}\medskip\\
    \hline
\endlastfoot
% table content
holder          &   holder  &   holder  & \cellcolor{green!25} no           \\
holder & holder & holder & \cellcolor{green!25} no \tnote{1}  \\
    \hline
holder holder holder holder holder & holder & \cellcolor{green!25} holder & \cellcolor{green!25} holder\\
    \hline
\textbf{holder} & holder & holder & holder \\
    \hline
holder & holder & holder & \cellcolor{green!25} no \tnote{2} \\
    \hline
holder holder holder holder holder & holder & \cellcolor{green!25} holder & \cellcolor{green!25} holder\\
    \hline
holder & holder & holder & \cellcolor{green!25} no \tnote{3} \\
    \hline
holder holder holder holder holder & holder & \cellcolor{green!25} holder & \cellcolor{green!25} holder holder\\
    \hline
\textbf{holder} & holder & holder & holder \\
    \hline
holder & holder & holder & \cellcolor{green!25} no \tnote{4} \\
    \hline
holder holder holder holder holder & holder & \cellcolor{green!25} holder & \cellcolor{green!25} holder\\
    \hline
holder & holder & holder & \cellcolor{green!25} no \tnote{5} \\
    \hline
holder holder holder holder holder & holder holder & \cellcolor{green!25} holder & \cellcolor{green!25} holder\\
    \hline
\textbf{holder} & holder & holder & holder \\
    \hline
holder & holder & holder & \cellcolor{green!25} no \tnote{6} \\
    \hline
holder holder holder holder holder & holder & \cellcolor{green!25} holder holder holder holder & \cellcolor{green!25} holder\\
    \hline
holder & holder & holder & \cellcolor{green!25} no \tnote{7} \\
    \hline
holder holder holder holder holder & holder & \cellcolor{green!25} holder & \cellcolor{green!25} holder\\
    \hline
\textbf{holder} & holder & holder & holder \\
    \hline
holder & holder & holder & \cellcolor{green!25} no \tnote{8} \\
    \hline
holder holder holder holder holder & holder & \cellcolor{green!25} holder & \cellcolor{green!25} holder\\
    \hline
holder & holder & holder & \cellcolor{green!25} no \tnote{1} \\
    \hline
holder holder holder holder holder & holder & \cellcolor{green!25} holder & \cellcolor{green!25} holder\\
    \hline
\textbf{holder} & holder & holder & holder \\
    \hline \hline
holder & holder & holder & \cellcolor{green!25} no \tnote{12} \\
    \hline
holder holder holder holder holder & holder & \cellcolor{green!25} holder & \cellcolor{green!25} holder\\
\end{tabularx}
    \end{ThreePartTable}
\end{document}
2
  • thank you very much for your answer. it fulfill my minimalistic expectation. however, testing it, i notice table behavior for which i didn't aware so far and for which i don't know a cause yet. to be more specific, i need to investigate more scenarios of table use. i will inform you about my findings.
    – Zarko
    Commented Nov 9, 2017 at 3:12
  • problems in testing of your solution has source in my misunderstanding how works longtable and have not any connection with your solution.
    – Zarko
    Commented Nov 9, 2017 at 6:42

You must log in to answer this question.

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