0

I am a beginner in terms of my knowledge of LaTeX and am attempting to create a longtable that spans two consecutive pages using longtblr within tabularray. By default, the alignment of the table caption is set to center. Furthermore, the separator between the caption text and label is ":" I was wondering how to change the alingment of the label and the caption to left. I would also like to change the separator to "." but I can't figure out how to do this based on my code, part of which I have pasted below:


\NewTblrTheme{fancy}{
  \SetTblrStyle{caption-tag}{font=\bfseries\fontsize{10}{12}\selectfont}
  \SetTblrStyle{caption-sep}{font=\bfseries\fontsize{10}{12}\selectfont}
  \SetTblrStyle{caption-text}{font=\fontsize{10}{12}\selectfont}
}
\begin{longtblr}[
  theme=fancy,
  caption = {Your table caption here},
  label = {tbl:mytable}, 
]{
  colspec={X[1]X[3]},
  rowhead=1,
  %row{1}={font=\bfseries, bg=white, fg=black},
  rowsep=0.5ex,
  %column{1}={font=\bfseries},
  width=0.9\linewidth}
}

I would be very grateful for the help. Thank you!

os306
  • 1

1 Answers1

2

Turns out that, while tabularray is a great package to do nice tables… it is not the most beginner friendly one when it comes to customization, as it relies on LaTeX3 syntax, which can be a jump in difficulty when someone is used to LaTeX2e.

I also can’t take full credit on this solution, since the one who actually took the work to show working modification on the source code was TheEndofTheWorld in this post. But here goes something that may help you!


\usepackage{tabularray}
\usepackage{xcolor} % Only if you want to color the cells

\begin{document}

% Edits on the tabularray defaults \ExplSyntaxOn \DefTblrTemplate{caption-sep}{default}{.\enskip} % Change ":" to "." \DefTblrTemplate{caption}{default} % Entire caption setup {% \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][l]{\box_use:N \l__tblr_caption_box} % "c" to "l" \par } } \ExplSyntaxOff

% Your custom style! \NewTblrTheme{fancy}{% \SetTblrStyle{caption-tag}{font=\bfseries\fontsize{10}{12}\selectfont} \SetTblrStyle{caption-sep}{font=\bfseries\fontsize{10}{12}\selectfont} \SetTblrStyle{caption-text}{font=\fontsize{10}{12}\selectfont} }

\begin{longtblr}[% theme = fancy, caption = {A fancy caption here}, label = {tbl:mytable} ]{% hlines, vlines, colspec = {X[1]X[3]}, rowhead = 1, rowsep = 0.5ex, width = 0.9\linewidth, row{1} = {font=\bfseries, bg=white, fg=black}, column{1} = {font=\bfseries} } Header & Second header\ First column & Second column\ First column & Second column\ First column & Second column\ First column & Second column\

\end{longtblr}

\end{document}

And this example yields the following table.

Output 1

So… what is going on? There are two modification on the “default” table loaded by tabularray here. The first on line 10 where the original said this...

\DefTblrTemplate{caption-sep}{default}{:\enskip}

And now we change it to this!

\DefTblrTemplate{caption-sep}{default}{.\enskip}

The contents of the last brackets tell what separator we are using. The \enskip command is just a hit of the space bar, but it can be pretty much edited to whatever. Don’t quote me on this, but in theory, setting the second bracket to “fancy” and pasting this before your original definition should have worked, but I have no idea why it didn’t on my end and is probably an issue with my build so… I’m just using dynamite to get rid of a fly because… hey! It works!

Line 11 contains the entire definition of the default caption, so wether we like it or not, we have to re-write everything in there to avoid making something crash. Therefore, lines 12 to 32 as exactly as the source code is.

Line 34 has the edit you need. The original line was this.

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

And now we have this!

\makebox[\hsize][l]{\box_use:N \l__tblr_caption_box}

The parameter in \makebox tells you the orientation of the contents. The original was c for centered, and now we use l for left!

Again, this all should work without moving the defaults on line 11 to “fancy” but… for some odd reason I can’t get it to work and I’m still scratching my head over why so… dynamite time it is!

I know this is not the easiest solution, but I hope that helps you edit what you need for your project!