[Tex/LaTex] Caption font size problem

fontsizetufte

I'm using the \documentclass{tufte-book} and have a series of longtables for which I wish to place the caption in the margin.

I found a solution to redefine the caption for such tables in this post, which worked perfectly.

\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

I'm also placing figures in the margin using the marginfigure but the font size for the captions of these are larger than the other text. I read in the Tufte Example Book that I can customise the style of margin content using (see pg31)…

\setsidenotefont{\footnotesize}
\setcaptionfont{\footnotesize}
\setmarginnotefont{\footnotesize}
\setcitationfont{\footnotesize}

…and these work, but they don't affect the size of fonts for marginfigure and there is no mention/description in the section on marginfigure (see pg23) of how to customise them either. However they all appear to be the same size in the example document

I had a search around and found the recommendation here to use the \usepackage[font=footnotesize]{caption} package/options, and this works, but it over-rides the custom caption defined for placing the caption of longtable in the margin, so its not really a viable option.

Can anyone advise as to how to modify the font size of captions in marginfigure or how to use the caption package but still define longtable captions to be placed in the margin?

Thanks in advance.

Best Answer

Since \marginpar won't work inside a float, I used Tikzpagenodes. It is easier to create separate replacements for figure and tables than combine the two.

\documentclass{article}
\usepackage{tikzpagenodes}
\usepackage{mwe}

% repacement caption
\newcommand{\figcaption}[1]% #1 = text
{\refstepcounter{figure}%
\addcontentsline{lof}{figure}{\numberline {\arabic{figure}}{\ignorespaces #1}}%
\tikz[remember picture,overlay]{\coordinate (here) at (0,0);%
\path (here -| current page marginpar area.west) node[below right,inner sep=0pt]
{\parbox{\marginparwidth}%
{\raggedright\footnotesize Figure \arabic{figure}:\newline{}#1}};}%
\newline\vspace{-\baselineskip}}%

\begin{document}

\listoffigures

\medskip
\lipsum[1]
\begin{figure}[htp]
\figcaption{A very very very very long caption.}
\centering\includegraphics{example-image}
\end{figure}
\lipsum[2]

\end{document}

full page