8

I want to create a custom table with tabularray package. I have used makecell and rotating packages to rotate some of the table cells. Additionally, the length of the rotated cells are set with \setlength\rotheadsize{} command and as it is expected, it affects all rotated cells. However, I want to set the size individually.

MWE:

\documentclass{article}
\usepackage[paperheight=6in,
   paperwidth=5in,
   top=10mm,
   bottom=20mm,
   left=10mm,
   right=10mm]{geometry}

\usepackage{tabularx}
\usepackage{tabularray}
\usepackage{makecell}
\usepackage{rotating}

\begin{document}
\begin{table}[ht]
\setlength\rotheadsize{2.0cm}
\renewcommand\theadfont{}
\begin{center}
  \begin{talltblr}[
    caption = {Example Table},
    label = {tbl:example},
  ]{
    width=\linewidth,
    colspec={X[1]X[12]|X[1]|X[1]|X[1]|X[1]|},
    cell{2}{3-6} = {halign=c,cmd=\rothead},
    cell{3-6}{1} = {halign=c,cmd=\rothead},
    vline{1}={3-Z}{solid},
    vline{2}={3-Z}{solid},
    rows = {c},
    column{2} = {l},
  }
    \cline{3-6}
    &  & \SetCell[c=4]{c} Some Text \\
    \cline{3-6}
    &  & Column 1 & Column 2 & Column 3 & Column 4 \\
    \cline{1-6}
    \SetCell[r=7]{c} Some longer text & Row 1        & X & X &   \\
    \cline{2-6}
    & Row 2        & X & X &   \\
    \cline{2-6}
    & Row 3        & X & X &   \\
    \cline{2-6}
    & Row 4       & X & X & X \\
    \cline{2-6}
    & Row 5     & X &   & X \\
    \cline{2-6}
    & Row 6     & X &   & X \\
    \cline{2-6}
    & Row 7     & X &   & X \\
    \hline
  \end{talltblr}
\end{center}
\end{table}
\end{document}

When the size is set for the rotated cells in 2nd row, the text in the 1st column becomes multiline. On the other hand, the height of the 2nd column becomes too high, when the size is set according to 1st column.

MVE

1
  • Welcome to TeX.SE! Good question!
    – Zarko
    Sep 28, 2022 at 23:12

3 Answers 3

5

Using your interesting answer as starting point, the possible (more consistent) solution for your problem can be :

\documentclass{article}
\usepackage{tabularray}
\usepackage{makecell}
\usepackage{rotating}

\begin{document}
    \begin{table}[ht]
    \caption{Example Table}
    \label{tbl:example}
    \renewcommand\theadfont{}
\centering
  \begin{tblr}{hline{1,2} = {3-Z}{solid}, vline{1,2} = {3-Z}{solid},
               hline{3-Z} = {solid}, vline{3-Z}={solid},
                  colspec = {c X[l] *{4}{c} },
                   row{2} = {cmd=\settowidth\rotheadsize{column 3 }\rothead},           % <---
                column{1} = {cmd=\settowidth\rotheadsize{Some longer text }\rothead},   % <---
                }
    &   & \SetCell[c=4]{c} Some Text 
            &   &   &           \\
    &   & Column 1 
            & Column 2
                & Column 3
                    & Column 4   \\
  \SetCell[r=7]{c}  Some longer text 
    & Row 1     & X &   &   &   \\
    & Row 2     &   & X &   &   \\
    & Row 3     &   &   & X &   \\
    & Row 4     &   &   &   & X \\
    & Row 5     &   &   & X &   \\
    & Row 6     &   & X &   &   \\
    & Row 7     & X &   &   &   \\
  \end{tblr}
\end{table}
\end{document}

which gives

enter image description here

As can be seen, in above MWE in table body is preserved usual way for writing cells contents and command for rotating is merged with settings of rotated cell sizes in table preamble.

3

Perhaps there is a better solution for this. For the time being, I would simply use \rotatebox[origin=c]{90}{...} in the affected cell

enter image description here

\documentclass{article}
\usepackage[paperheight=6in,
   paperwidth=5in,
   top=10mm,
   bottom=20mm,
   left=10mm,
   right=10mm]{geometry}

\usepackage{tabularray}
\usepackage{makecell}
\usepackage{rotating}

\begin{document}
\begin{table}[ht]
\settowidth{\rotheadsize}{Column 4}
\renewcommand\theadfont{}
\begin{center}
  \begin{talltblr}[
    caption = {Example Table},
    label = {tbl:example},
  ]{
    width = 0.8\linewidth,
    colspec = {X X[12] *4{X}},
    cell{2}{3-6} = {halign=c,cmd=\rothead},
    vline{1} = {3-Z}{solid},
    vline{2} = {3-Z}{solid},
    vline{3-Z} = {},
    hline{1,2} = {3-6}{},
    hline{3-Z} = {},
    rows = {c},
    column{2} = {l},
  }
    &  & \SetCell[c=4]{c} Some Text \\
    &  & Column 1 & Column 2 & Column 3 & Column 4 \\
    \SetCell[r=7]{} \rotatebox[origin=c]{90}{Some longer text}
    & Row 1 & X & X &   &   \\
    & Row 2 &   & X & X &   \\
    & Row 3 &   & X & X &   \\
    & Row 4 &   & X & X & X \\
    & Row 5 &   & X &   & X \\
    & Row 6 &   & X &   & X \\
    & Row 7 &   & X &   & X \\
  \end{talltblr}
\end{center}
\end{table}
\end{document}
1

Instead of using \rothead command as a parameter of cell, I used it in place and gave \setlength and \settowidth commands as a cell parameter.

\documentclass{article}
% Using the geometry package with a small
% page size to create the article graphic
\usepackage[paperheight=6in,
   paperwidth=5in,
   top=10mm,
   bottom=20mm,
   left=10mm,
   right=10mm]{geometry}

\usepackage{tabularx}
\usepackage{tabularray}
\usepackage{makecell}
\usepackage{rotating}

\begin{document}
\begin{table}[ht]
% \setlength\rotheadsize{2.0cm}
\renewcommand\theadfont{}
\begin{center}
  \begin{talltblr}[
    caption = {Example Table},
    label = {tbl:example},
  ]{
    width=\linewidth,
    colspec={X[1]X[12]|X[1]|X[1]|X[1]|X[1]|},
    cell{2}{3-6} = {halign=c,cmd=\setlength\rotheadsize{1.5cm}},
    cell{3-6}{1} = {halign=c,cmd=\settowidth\rotheadsize{\theadfont Some longer text}},
    vline{1}={3-Z}{solid},
    vline{2}={3-Z}{solid},
    rows = {c},
    column{2} = {l},
  }
    \cline{3-6}
    &  & \SetCell[c=4]{c} Some Text \\
    \cline{3-6}
    &  & \rothead{Column 1} & \rothead{Column 2} & \rothead{Column 3} & \rothead{Column 4} \\
    \cline{1-6}
    \SetCell[r=7]{c} \rothead{Some longer text} & Row 1        & X & X &   \\
    \cline{2-6}
    & Row 2        & X & X &   \\
    \cline{2-6}
    & Row 3        & X & X &   \\
    \cline{2-6}
    & Row 4       & X & X & X \\
    \cline{2-6}
    & Row 5     & X &   & X \\
    \cline{2-6}
    & Row 6     & X &   & X \\
    \cline{2-6}
    & Row 7     & X &   & X \\
    \hline
  \end{talltblr}
\end{center}
\end{table}
\end{document}

Solution Result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.