4

Code

Consider the following example:

\DocumentMetadata{}

\documentclass{article}

\usepackage[margin = 1.8cm]{geometry} % to avoid `overfull \hbox'
\usepackage{tabularray}

\begin{document}

\begin{tblr}{
  hline{1}   = {2-7}{solid},
  hline{2-Z} = {solid},
  vline{1}   = {2-7}{solid},
  vline{2-Z} = {solid}
}
  & \SetCell{c, m, 1.75cm}
    Utilstræk\-keligt
  & \SetCell{c, m, 1.75cm}
    Tilstræk\-keligt
  & \SetCell{c, m, 1.75cm}
    Jævnt
  & \SetCell{c, m, 1.75cm}
    Godt
  & \SetCell{c, m, 1.75cm}
    Frem\-ragende \\
    \SetCell[r = 1]{h, m, 5.9cm}
    Samarbejdet har fungeret og eventuelle problemer er blevet løst
  &
  &
  &
  &
  &  \\
    \SetCell[r = 1]{h, m, 5.9cm}
    Tiden er blevet disponeret fornuftigt
  &
  &
  &
  &
  &  \\
\end{tblr}%

\end{document}

The tabularray package is fairly new to me.

Question

Can the code somehow be improved? (I know that this is a subjective question.)

2
  • 2
    Unrelated to your code, but your table would look more professional without all the vertical lines. Feb 28 at 13:41
  • 1
    @samcarter_is_at_topanswers.xyz I totally agree; the problem is that some of my students have a really head time focusing, so marked cells for everything helps them to some extend. Thanks for you suggestion, none the less. Feb 28 at 16:22

2 Answers 2

5
  • Instead of specifying the alignment for each cell individually, you could do this globally in the table settings

  • Instead of hard coding the width of the cells, I would let tabularray do this for you. If you use X columns, tabularray will automatically distribute them evenly and with something like X[4] you can make the first column wider than the other columns.


\DocumentMetadata{}

\documentclass{article}

\usepackage[margin = 1.8cm]{geometry} % to avoid `overfull \hbox'
\usepackage{tabularray}

\begin{document}

\begin{tblr}{
  cells={m,c},
  colspec={X[4,l,h]XXXXX},
  hline{1}   = {2-7}{solid},
  hline{2-Z} = {solid},
  vline{1}   = {2-7}{solid},
  vline{2-Z} = {solid}
}
  & Utilstræk\-keligt
  & Tilstræk\-keligt
  & Jævnt
  & Godt
  & Frem\-ragende \\
  Samarbejdet har fungeret og eventuelle problemer er blevet løst
  &
  &
  &
  &
  &  \\
  Tiden er blevet disponeret fornuftigt
  &
  &
  &
  &
  &  \\
\end{tblr}%

\end{document}

enter image description here

2
  • 1
    Thank you very much! I can see from your screenshot that the last column is slightly wider than the other four -- can I somehow make all five exactly the same width? (I'm not near a computer at the moment so I can't try myself.) Feb 28 at 16:21
  • 2
    @SvendTveskæg Fixed! I forgot one X in the columns declaration, sorry! Feb 28 at 20:43
5

For information, here is a way to create that table with {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage[margin = 1.8cm]{geometry} 
\usepackage{nicematrix}
\usepackage{varwidth}

\begin{document}

\begin{NiceTabular}{V[l]{7cm}*{5}{X[c]}}[hvlines,corners=NW,cell-space-limits=3pt]
  & Utilstræk\-keligt
  & Tilstræk\-keligt
  & Jævnt
  & Godt
  & Frem\-ragende \\
  Samarbejdet har fungeret og eventuelle problemer er blevet løst \\
  Tiden er blevet disponeret fornuftigt \\
\end{NiceTabular}

\end{document}

You need several compilations (because nicematrix uses PGF/TikZ nodes under the hood).

Output of the above code

You must log in to answer this question.

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