5

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}[caption={one table}]{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.

  • 1
    I think you should clarify if you want a longtblr solution. If so, I think you have to redefine some commands of the package, which is unfortunately not that easy. Maybe contact the package author for further help. – marv Dec 20 '21 at 07:49
  • Yes, I want a longtblr solution! I redefined the commands and, for me, worked. – TheEndofTheWorld Dec 20 '21 at 13:50

2 Answers2

2

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

  • Thank you for your comment! I was looking to a more automatic solution, with the internal commands of the tabularray package, fortunately I found it! – TheEndofTheWorld Dec 20 '21 at 13:48
2

I found a solution! You need to redefine/create a template command. I used the code bellow to redefine the default template.

\DefTblrTemplate { caption } { normal }
{
\hbox_set:Nn \l__tblr_caption_box
{
\UseTblrTemplate { caption-tag } { default }
\UseTblrTemplate { caption-sep } { default }
\UseTblrTemplate { caption-text } { default }
}
\dim_compare:nNnTF { \box_wd:N \l__tblr_caption_box } > { \hsize }
{
\UseTblrAlign { caption }
\UseTblrIndent { caption }
\hbox_set:Nn \l__tblr_caption_left_box
{
\UseTblrTemplate { caption-tag } { default }
\UseTblrTemplate { caption-sep } { default }
}
\hangindent = \box_wd:N \l__tblr_caption_left_box
\hangafter = 1
\UseTblrHang { caption }
\leavevmode
\hbox_unpack:N \l__tblr_caption_box
\par
}
{
\centering
\makebox [\hsize] [c] { \box_use:N \l__tblr_caption_box }
\par
}
}

I redefined the default style to this:

 \DefTblrTemplate { caption } { default }
{
    \hbox_set:Nn \l__tblr_caption_box
    {
        \UseTblrTemplate { caption-tag } { default }
        \UseTblrTemplate { caption-sep } { default }
        \UseTblrTemplate { caption-text } { default }
    }
    \dim_compare:nNnTF { \box_wd:N \l__tblr_caption_box } > { \hsize }
        {
            \UseTblrAlign { caption }
            \UseTblrIndent { caption }
            \hbox_set:Nn \l__tblr_caption_left_box
            {
                \UseTblrTemplate { caption-tag } { default }
                \UseTblrTemplate { caption-sep } { default }
            }
            \hangindent = \box_wd:N \l__tblr_caption_left_box
            \hangafter = 1
            \UseTblrHang { caption }
            \leavevmode
            \hbox_unpack:N \l__tblr_caption_box
            \par
        }
        {
            \marginnote { \box_use:N \l__tblr_caption_box }
            \par
        }
}

Here I changed these lines of placement:

\centering
    \makebox [\hsize] [c] { \box_use:N \l__tblr_caption_box }
    \par

To these lines:

\marginnote { \box_use:N \l__tblr_caption_box }
            \par

Now the caption is in the margin. Unfortunately, the \marginpar command does not work, if you try to use it, you will get the error: ! LaTeX Error: Not in outer par mode. So, you need to use the package marginnote to get the correct command.

The complete code:

\documentclass[12pt, mpinclude]{scrbook}

\usepackage{tabularray} \usepackage{marginnote} \begin{document}

\ExplSyntaxOn \DefTblrTemplate { caption } { default } { \hbox_set:Nn \l__tblr_caption_box { \UseTblrTemplate { caption-tag } { default } \UseTblrTemplate { caption-sep } { default } \UseTblrTemplate { caption-text } { default } } \dim_compare:nNnTF { \box_wd:N \l__tblr_caption_box } > { \hsize } { \UseTblrAlign { caption } \UseTblrIndent { caption } \hbox_set:Nn \l__tblr_caption_left_box { \UseTblrTemplate { caption-tag } { default } \UseTblrTemplate { caption-sep } { default } } \hangindent = \box_wd:N \l__tblr_caption_left_box \hangafter = 1 \UseTblrHang { caption } \leavevmode \hbox_unpack:N \l__tblr_caption_box \par } { \marginnote { \box_use:N \l__tblr_caption_box } \par } } \ExplSyntaxOff

\DefTblrTemplate{caption-tag}{default}{Tabela\hspace{0.25em}\thetable} \DefTblrTemplate{caption-sep}{default}{-\enskip} \DefTblrTemplate{caption-text}{default}{\InsertTblrText{caption}} \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}

The output:

enter image description here