3

I use Pandoc to generate LaTeX, which uses longtable. By default table captions for longtable do not get placed in the margin. Based on this answer a working solution is the following hack:

\makeatletter
\def\LT@makecaption#1#2#3{%
    \noalign{\smash{\hbox{\kern\textwidth\rlap{\kern\marginparsep
    \parbox[t]{\marginparwidth}{\vspace{10pt}%
\@tufte@caption@font\@tufte@caption@justification\noindent
    #1{#2:~}\ignorespaces#3}}}}}}
\makeatother

Caption in the outer margin using longtable within a tufte-latex document

However, this always places the caption on the right. Using the symmetric document option, the margin alternates, and this therefore breaks margin placement. This is using the latest TinyTeX with the XeTeX engine (though PDFTeX doesn't shows the same error).

Another minor issue is that even on pages with right margins the captions are slightly indented horizontally and line spacing seems off?

Broken caption placement: Broken caption placement


Showing slightly indented margin caption: Showing slightly indented margin caption

M[non]WE:

\documentclass[symmetric,nobib]{tufte-book}

\usepackage{longtable,booktabs}

% fix longtable captions: % https://tex.stackexchange.com/questions/182653/caption-in-the-outer-margin-using-longtable-within-a-tufte-latex-document \makeatletter \def\LT@makecaption#1#2#3{% \noalign{\smash{\hbox{\kern\textwidth\rlap{\kern\marginparsep \parbox[t]{\marginparwidth}{\vspace{10pt}% @tufte@caption@font@tufte@caption@justification\noindent #1{#2:~}\ignorespaces#3}}}}}} \makeatother

\begin{document}

\begin{table}[h] \centering \begin{tabular}{lcr} \toprule Heading & Style & Size \ \midrule Part & roman & {40} \ Chapter & italic & {40} \ Section & italic & {26} \ Subsection & italic & {26} \ Paragraph & italic & 10/14 \ \bottomrule \end{tabular} \caption{This is a table with a caption. This is some filler text.} \end{table}

Here is some text.\marginnote{This is a marginnote.}

\begin{longtable}[]{@{}lll@{}} \caption{This is a longtable with a caption. This is some filler text.}\tabularnewline \toprule\noalign{} Sun & Earth & Moon \ \midrule\noalign{} \endfirsthead \toprule\noalign{} Sun & Earth & Moon \ \midrule\noalign{} \endhead \bottomrule\noalign{} \endlastfoot A & D & G \ B & E & H \ C & F & I \ \end{longtable}

\newpage

\begin{table}[h] \centering \begin{tabular}{lcr} \toprule Heading & Style & Size \ \midrule Part & roman & {40} \ Chapter & italic & {40} \ Section & italic & {26} \ Subsection & italic & {26} \ Paragraph & italic & 10/14 \ \bottomrule \end{tabular} \caption{This is a table with a caption. This is some filler text.} \end{table}

Here is some text.\marginnote{This is a marginnote.}

\begin{longtable}[]{@{}lll@{}} \caption{This is a longtable with a caption. This is some filler text.}\tabularnewline \toprule\noalign{} Sun & Earth & Moon \ \midrule\noalign{} \endfirsthead \toprule\noalign{} Sun & Earth & Moon \ \midrule\noalign{} \endhead \bottomrule\noalign{} \endlastfoot A & D & G \ B & E & H \ C & F & I \ \end{longtable}

\end{document}

The Tentacle
  • 133
  • 5

1 Answers1

2

This is just David's answer made symmetric, so you will need to make the same adjustments for vertical positioning, if you want them:

\documentclass[symmetric]{tufte-book}

\usepackage{booktabs} \usepackage{longtable}

\makeatletter \def\LT@makecaption#1#2#3{% ateb David Carlisle: https://tex.stackexchange.com/a/183344/ -> +symmetry: https://tex.stackexchange.com/a/701116/ \ifodd\c@page \noalign{% \smash{% \hbox{\kern\textwidth\kern-\parindent\rlap{\kern\marginparsep \parbox[t]{\marginparwidth}{% @tufte@caption@font @tufte@caption@justification \noindent #1{#2: }\ignorespaces #3}}% }% }% }% \else \noalign{% \smash{% \hbox{\llap{% \parbox[t]{\marginparwidth}{% @tufte@caption@font @tufte@caption@justification \noindent #1{#2: }\ignorespaces #3}% \kern\marginparsep }% }% }% }%
\fi } \makeatother

\begin{document}

\begin{table}[h] \centering \begin{tabular}{lcr} \toprule Heading & Style & Size \ \midrule Part & roman & {40} \ Chapter & italic & {40} \ Section & italic & {26} \ Subsection & italic & {26} \ Paragraph & italic & 10/14 \ \bottomrule \end{tabular} \caption{Heading styles used in.} \end{table}

\begin{longtable}{lcccc} \caption{Verification methods.}\ \toprule Requirement id & Review of design & Analysis & Inspection & Test \ \toprule \endfirsthead \toprule Requirement id & Review of design & Analysis & Inspection & Test \ %\otoprule \endhead \bottomrule \endfoot One & * & & & \ \midrule Two & * & & & \ \midrule Three & * & & & \ \midrule Four & * & & & \ \end{longtable}

\clearpage

\begin{longtable}{lcccc} \caption{Verification methods.}\ \toprule Requirement id & Review of design & Analysis & Inspection & Test \ \toprule \endfirsthead \toprule Requirement id & Review of design & Analysis & Inspection & Test \ %\otoprule \endhead \bottomrule \endfoot One & * & & & \ \midrule Two & * & & & \ \midrule Three & * & & & \ \midrule Four & * & & & \ \end{longtable}

\end{document}

The following adds a frame to demonstrate relationships to page layout. This shows the corrected horizontal alignment, but vertical adjustments would need to be added as explained in David's comments on his original answer.

symmetric hacked captions

cfr
  • 198,882
  • Thank you for your suggested code — this works well in the MWE[1]. For vertical offset adding \vspace{} as @david-carlile suggested works well, but do you know how to solve the horizontal indent compared to other marginalia; you can see it clearly if you add \usepackage{lua-visual-debug} to the MWE… – The Tentacle Nov 13 '23 at 12:25
  • @TheTentacle See edit. You should only need the adjustment for odd pages. I added showframe to debug using pdfTeX. You still need to use the vertical adjustments, but the horizontal should, I think, be automatic. But note that tufte really does these things very differently and I'm not at all familiar with the class. – cfr Nov 13 '23 at 16:40
  • Thank you so much! On odd pages this is now horizontally aligned, however it seems on even pages there is still a horizontal offset (I show a marginnote above the caption, the marginnote is aligned to the header page number): https://imgbox.com/3L5nCBy1 – The Tentacle Nov 15 '23 at 04:20
  • @TheTentacle I think you should ask David in that case. I really don't know what tufte does with captions, but it is very non-standard. All I did was fiddle with David's code in a couple of obvious(ish) places. I don't want to be the cause of chaos ;). – cfr Nov 15 '23 at 04:36
  • Great, thank you, I will accept your answer as it solves the main problems. It is fragile for longer docs with other margin content (sometimes breaks, sometimes doesn't), I suspect the rules governing margin content are complex... – The Tentacle Nov 17 '23 at 06:25
  • @TheTentacle Marginalia are difficult to deal with even in the standard classes, where you're not dealing with captions. They tend to move and end up on the wrong pages or disappear altogether. I don't know whether the new LaTeX core stuff coming out will help, but fingers crossed. – cfr Nov 17 '23 at 06:28