[Tex/LaTex] Caption in the outer margin using longtable within a tufte-latex document

captionslongtabletablestufte

The tufte-latex class has a page layout with a wide margin on the side; the class redefines the figure and table environments so that the captions are put in the margin, side to side with the floating environment.
Here's an excerpt from the sample-book.pdf file:Example of table and its caption in the tufte-latex class
However, there's a problem when using the longtable environment.
Since it cannot be put inside a table environment, it loses the caption in the margin.

Longtable in fact has a \caption{} command, but it allows the caption to be placed only on top on the table, not on the side (that is, in the margin):
Longtable environment with wrong caption placement

How can I have a longtable with the caption in the margin?

tufte-latex places the caption in the margin, aligned with the top of the floating environment, and it can be serif (default) or sans-serif (\sffamily).

I'm aware of this answer, but it does not solve the problem completely, as the longtable caption does not inherit the format of the other captions.

A MWE as requested (longtable with the wrong caption):

\documentclass{tufte-book}

\usepackage{booktabs}
\usepackage{longtable}

\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}

\end{document}

Best Answer

Basically you can use the code in the referenced answer but replace the \raggedright by the formatting the Tufte class uses. I don't really know that class but using \tracingall suggests that this produces the same formatting (but the class may have higher level access to these settings)

enter image description here

\documentclass{tufte-book}

\usepackage{booktabs}
\usepackage{longtable}

\makeatletter
\def\LT@makecaption#1#2#3{%
  \noalign{\smash{\hbox{\kern\textwidth\rlap{\kern\marginparsep
  \parbox[t]{\marginparwidth}{%
\@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{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}

\end{document}