Tables – Using Package Tabularray with Side Caption

captionssidecaptablestabularray

I am using the very nice package tabularray and I want to put the caption of the table on the side margin (like Tufte-Style), but I did not find a way to do it. In the documentation (4.2.3 of the manual) I just found a way to customize the font and other options, with the commands:

\DefTblrTemplate{caption-tag}{default}{Table\hspace{0.25em}\thetable}
\DefTblrTemplate{caption-sep}{default}{:\enskip}
\DefTblrTemplate{caption-text}{default}{\InsertTblrText{caption}}

But this does not affect the position of the caption.

Here a very MWE:

\documentclass[12pt, mpinclude]{scrbook}

\usepackage{tabularray}

\begin{document}

\DefTblrTemplate{caption-tag}{default}{Tabela\hspace{0.25em}\thetable}
\DefTblrTemplate{caption-sep}{default}{-\enskip}
\DefTblrTemplate{caption-text}{default}{\InsertTblrText{caption}}
\begin{longtblr}{colspec = {X[c]X[c]X[c]}}
1 &  2& 3 &\\
4 & 5& 6\\
7 & 8 & 9 \\
\end{longtblr}
\end{document}

EDIT: I mentioned the Tufte-Style just because I am trying to reproduce this style in a document and it uses all captions in the margin, but I am not using this specific class.

Best Answer

A simple solution is to remove the standard caption entirely, and the use \captionof in a \marginpar. \captionof is a standard command in soma-script, otherwise you would have to use a package like caption.

\documentclass[12pt, mpinclude]{scrbook}

\usepackage{tabularray}

\setcapindent{0pt}

\begin{document}

\DefTblrTemplate{caption-tag}{default}{}
\DefTblrTemplate{caption-sep}{default}{}
\DefTblrTemplate{caption-text}{default}{}
\renewcommand{\tablename}{Tabela}

\marginpar{\captionof{table}{\null\\one table}}
\begin{longtblr}[caption={one table}]{colspec = {X[c]X[c]X[c]}}
1 &  2& 3 &\\
4 & 5& 6\\
7 & 8 & 9 \\
\end{longtblr}
\end{document}

enter image description here

Related Question