1

I have two tables which are about 40% of the page height. Both are related and should stay on the same page. Therefore I put both tables inside a minipage and made it floating.

\documentclass{tufte-book}
\usepackage{booktabs,tabularx,cleveref,lipsum}
\usepackage{capt-of}

%% get fullwidth length
\makeatletter
\newlength{\fullwidthlength}
\AtBeginDocument{\setlength{\fullwidthlength}{\@tufte@fullwidth}}
\makeatother

%% custom floating environment
% this puts the minipage on a separate page
\usepackage{float}
\newfloat{floatingminipage}{p}{fm}[section]

\begin{document}
\begin{floatingminipage}
\begin{minipage}{\fullwidthlength}\centering
    \begin{tabularx}{.95\linewidth}{XX}
    \toprule
    1 & 2 \\
    \bottomrule
    \end{tabularx}
    \captionof{table}{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}
    \label{tbl:one} 

\vspace*{2cm}   

    \begin{tabularx}{.95\linewidth}{XX}
    \toprule
    1 & 2 \\
    \bottomrule
    \end{tabularx}
    \captionof{table}{Cras sodales pharetra ultrices. Morbi suscipit malesuada neque sit amet laoreet. See \cref{tbl:one}}
    \label{tbl:two} 

\end{minipage} 
\end{floatingminipage}
\end{document}

enter image description here

The only thing is I cannot get the captions to be of \marginparwidth and inside the margin directly under the table. I tried the following

\usepackage{xparse}
\let\latexCaptionOf\captionof
% arguments:
% #1 short caption
% #2 offset
% #3 figure type (table, figure)
% #4 caption text
\RenewDocumentCommand{\captionof}{o O{0mm} m m}{%
    \begin{minipage}[b]{\linewidth}\par\hfill\raisebox{#2}[\height]{%
            \begin{minipage}[b]{\marginparwidth}%
                \IfValueTF{#1}{\latexCaptionOf{#3}[#1]{#4}}%
                {\latexCaptionOf{#3}{#4}}%
            \end{minipage}}%
        \end{minipage}% 
}%

but the label does not get resolved anymore and just shows ??.

enter image description here

I don't know if my approach is reasonable and any better solutions are welcome. I just need these two table on the same floating page such that labels get resolved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.