2

The following longtblr table code and myself have some differences of opinion. For instance, the font size, which I would like to be 10pt, but the output just puts "10pt" above the table and then goes on to do what it wants to.

\documentclass[a4paper]{article}
\usepackage[top=2cm, bottom=3cm, left=3.5cm, right=3.5cm]{geometry}
\usepackage{tabularray}

\NewTblrTheme{mytable}{
  %\SetTblrStyle{head}{bg=teal7}
  \SetTblrStyle{contfoot-text}{normal}{font=\footnotesize\itshape}
  \SetTblrStyle{caption-sep}{normal}{\enskip\(|\)\enskip}
}

\begin{document}
\begin{longtblr}[
    theme = mytable,
    caption = A very long table,
    font=10pt,
  ]{
    colspec = {X[l,2cm] m{7cm} Q[c] Q[c]}, 
    width = \linewidth,
    rowhead = 1,
    row{1} = {teal7},
  }
      \hline[1.5pt]
      column 1 & column 2 & column 3 & column 4 \\
      \hline
      row & some relatively long description so that the other entries can showboat their floatiness & row & \SetCell[r=2]{c} rows centred in two \\
      row & less showboating, maybe even no showboating & row & \\
      row & some relatively long description so that the other entries can showboat their floatiness & row & \SetCell[r=2]{c} rows \\
      row & less showboating, maybe even no showboating & row & \\
      row & some relatively long description so that the other entries can showboat their floatiness & row & \SetCell[r=2]{c} rows \\
      row & less showboating, maybe even no showboating & row & \\
      row & some relatively long description so that the other entries can showboat their floatiness & row & \SetCell[r=2]{c} rows \\
      row & less showboating, maybe even no showboating & row & \\
      row & some relatively long description so that the other entries can showboat their floatiness & row & \SetCell[r=2]{c} rows \\
      row & less showboating, maybe even no showboating & row & \\
      row & some relatively long description so that the other entries can showboat their floatiness & row & \SetCell[r=2]{c} rows \\
      row & less showboating, maybe even no showboating & row & \\
      row & some relatively long description so that the other entries can showboat their floatiness & row & \SetCell[r=2]{c} rows \\
      row & less showboating, maybe even no showboating & row & \\
      row & some relatively long description so that the other entries can showboat their floatiness & row & \SetCell[r=2]{c} rows \\
      row & less showboating, maybe even no showboating & row & \\
      row & some relatively long description so that the other entries can showboat their floatiness & row & \SetCell[r=2]{c} rows \\
      row & less showboating, maybe even no showboating & row & \\
      row & some relatively long description so that the other entries can showboat their floatiness & row & \SetCell[r=2]{c} rows \\
      row & less showboating, maybe even no showboating & row & \\
\end{longtblr}
\end{document}
}

Any thoughts?


Edited to reduce the errors in the example. However, it appears I have misunderstood the package documentation. To me, it appears as though the colours and font command are loaded with the package, while the first commenter has told me to fix those. Also, it appears as though it's not really \linewidth.

1
  • 3
    I'm getting multiple syntax error messages: 1) the misplaced } at the end, 2) \DefTblrStyle isn't defined, 3) font option isn't defined, 4) and after that other errors about colors… Can you first provide a correct example? After that, the font option is normally used as an argument to the cell or cells option.
    – Miyase
    Apr 10 at 8:17

2 Answers 2

5

Considered @Miyase an @CarLaTeX comments:

\documentclass[a4paper,12pt]{article}
\usepackage[hmargin= 3.5cm,
            vmargin={2cm, 3cm}]{geometry}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage{kantlipsum}

\NewTblrTheme{mytable}{
  \SetTblrStyle{firstfoot,middlefoot}{\footnotesize\itshape}
  \DefTblrTemplate{caption-sep}{default}{\enskip\(|\)\enskip}
}

\begin{document}
\kant[1-3]

\begin{longtblr}[
  theme = mytable,
caption = {A very long table},
  label = {tab:long...}
                ]{colspec = {l X[j, m] c c},
                  cells   = {font = \fontsize{10pt}{12pt}\selectfont},
                  row{1}  = {teal9},
                  rowhead = 1,
                  }
    \toprule
column 1 & column 2 & column 3  & column 4 \\
    \midrule
row      & some relatively long description so that the other entries can showboat their floatiness
                    & row       & rows \\
row      & some relatively long description so that the other entries can showboat their floatiness
                    & row       & rows \\
row      & some relatively long description so that the other entries can showboat their floatiness
                    & row       & rows \\
row      & some relatively long description so that the other entries can showboat their floatiness
                    & row       & rows \\
row      & some relatively long description so that the other entries can showboat their floatiness
                    & row       & rows \\
row      & some relatively long description so that the other entries can showboat their floatiness
                    & row       & rows \\
row      & some relatively long description so that the other entries can showboat their floatiness
                    & row       & rows \\
row      & some relatively long description so that the other entries can showboat their floatiness
                    & row       & rows \\
row      & some relatively long description so that the other entries can showboat their floatiness
                    & row       & rows \\
row      & some relatively long description so that the other entries can showboat their floatiness
                    & row       & rows \\
row      & some relatively long description so that the other entries can showboat their floatiness
                    & row       & rows \\
    \bottomrule
\end{longtblr}

\kant[4]
\end{document}

enter image description here

4

I slightly streamlined and definitely cleaned your code from errors. If you are going to customise longtblr, you should read the documentation, mostly the part related to longtblr. It's not so easy to understand at first but makes sense once you have got the idea how themes and custom styles work.

I didn't understand the problem with font size because 10pt is the default one in regular documents. However, it's possible to set a specific font size for you table, even though document is set to let's say 12pt (see example). Make sure you put table with \fontsize in a group, so it affects only the table.

Here's a working code you can take from. I added a few paragraphs of dummy texts to compare the table with regular content.

\documentclass[a4paper,12pt]{article}
\usepackage[top=2cm, bottom=3cm, left=3.5cm, right=3.5cm]{geometry}
\usepackage{xcolor}
\usepackage{tabularray}
\usepackage{kantlipsum}

\NewTblrTheme{mytable}{
  \SetTblrStyle{firstfoot,middlefoot}{\footnotesize\itshape}
  \DefTblrTemplate{caption-sep}{default}{\enskip\(|\)\enskip}
}

\begin{document}
\kant[1-2]

\begingroup
\fontsize{10pt}{12pt}\selectfont
\begin{longtblr}[
    theme = mytable,
    caption = {A very long table},
  ]{
    colspec = {X[l] Q[7cm,m] Q[c] Q[c]}, 
    width = \linewidth,
    row{1} = {teal7},
    hline{1,Z} = {wd=1.5pt},
    hline{2} = {},
    cell{even[2-Z]}{4} = {r=2}{},
    rowhead = 1,
  }
  column 1 & column 2 & column 3 & column 4 \\
  row & some relatively long description so that the other entries can showboat their floatiness & row & rows \\
  row & less showboating, maybe even no showboating & row & \\
  row & some relatively long description so that the other entries can showboat their floatiness & row & rows \\
  row & less showboating, maybe even no showboating & row & \\
  row & some relatively long description so that the other entries can showboat their floatiness & row & rows \\
  row & less showboating, maybe even no showboating & row & \\
  row & some relatively long description so that the other entries can showboat their floatiness & row & rows \\
  row & less showboating, maybe even no showboating & row & \\
  row & some relatively long description so that the other entries can showboat their floatiness & row & rows \\
  row & less showboating, maybe even no showboating & row & \\
  row & some relatively long description so that the other entries can showboat their floatiness & row & rows \\
  row & less showboating, maybe even no showboating & row & \\
  row & some relatively long description so that the other entries can showboat their floatiness & row & rows \\
  row & less showboating, maybe even no showboating & row & \\
  row & some relatively long description so that the other entries can showboat their floatiness & row & rows \\
  row & less showboating, maybe even no showboating & row & \\
  row & some relatively long description so that the other entries can showboat their floatiness & row & rows \\
  row & less showboating, maybe even no showboating & row & \\
  row & some relatively long description so that the other entries can showboat their floatiness & row & rows \\
  row & less showboating, maybe even no showboating & row & \\
\end{longtblr}
\endgroup

\kant[2]
\end{document}

enter image description here

2
  • 4
    tabularray has the font= option (you can use it in rows=, for example) no need to use \begingroup/\endgroup.
    – CarLaTeX
    Apr 10 at 9:53
  • Thanks. I can see that in Zarko's answer. I didn't realise we could also use \fontsize in cell settings. I'll leave code as is since Zarko provided code with the preferred approach.
    – Celdor
    Apr 10 at 11:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .