[Tex/LaTex] Multirow and rotated column headers

calculationsdimensionstables

I want to typeset a table with rotatetd column headers (so far it works) stretching over multiple rows.

The problem seems to be that multirow does not adjust the tables row heights, thus I have to do this by hand, and I struggle with this.

Using a slightly adopted solution from Werner (https://tex.stackexchange.com/a/32687/19326), I get the rotating and can have line breaks.

I now want to calculate the height by which I have to stretch my "stretch column".
The value I need to calculate is obviously the height of my rotated box, minus the heights of the rows that I am spanning.

How do I retrieve the height of a row?
What is the easiest way to calculate objectheight - rowheight1 -rowheight2?

Here is the code I have so far:

\documentclass{report}
\usepackage{xparse}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{pbox}
\usepackage{rotating}
\usepackage{calc}
%\NewDocumentCommand{\rot}{O{90} O{1em} m}{\makebox[#2][l]{\rotatebox{#1}{\pbox[t]{\textwidth}{#3}}}}%
\NewDocumentCommand{\rot}{O{90} O{1em} m}{\makebox[#2][l]{\begin{turn}{#1}{\pbox[t]{\textwidth}{#3}}\end{turn}}}%
\begin{document}

\newlength{\myl}
\settowidth{\myl}{Long Long}

\the\myl

\begin{tabular}{cccc}
\toprule
& \multirow{3}{*}{\rot{Long Long\\ text}}& & \\[\the\myl] %column which I want to stretch
Sample & & \multicolumn{2}{c}{Group} \\
\rot{a} & & A & B \\
\midrule
data & data & data & data \\
\bottomrule
\end{tabular}


\widthof{test}
\end{document}

Note: I would like to use \widthof{test} since this appears easier to me than the length fiddling, however the \widthof{test} command actually typesets test in my case.

I looked at Text in rotated multirow cell crosses table border (Basically where I got the idea to adjust the row height from, however I am not sure that my rowheight will always be \normalbaselineskip) and How to rotate text in multirow table? which does not help since it is concerned about the positioning of the rotated text rather than stretching the group of rows to accomodate the text.

Best Answer

The makecell package has all the tools required for that. It allows for line breaks in cells, a common formatting of column heads, and multiline rotated heads. Here are threevariants of what can be done very simply:

\documentclass{report}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{rotating, multirow}
\usepackage{makecell}
\renewcommand\theadfont{\bfseries}

\begin{document}

\settowidth{\rotheadsize}{\bfseries Long long\quad}
\begin{tabular}[t]{cccc}
  \toprule
\addlinespace[-2ex]
  \thead{Sample }& \rothead{Long long\\ text}& \multicolumn{2}{c}{\thead{Group}} \\
  \turnbox{90}{a} & & A & B \\
  \midrule
  data & data & data & data \\
  \bottomrule
\end{tabular}
\qquad
\renewcommand\theadalign{bc}
\begin{tabular}[t]{cccc}%
  \toprule
  \addlinespace[6.5ex]%
  \thead{Sample } && \multicolumn{2}{c}{\thead{Group}} \\%[6.5ex]
  \turnbox{90}{a} &\multirowthead{-4}[0.3ex]{\rothead{\\[5ex]Long long\\ text}} & A & B \\
  \midrule
  data & data & data & data \\
  \bottomrule
\end{tabular}
\vskip1cm
\begin{tabular}[t]{cccc}%
  \toprule
  \addlinespace[4ex]%
  \thead{Sample } && \multicolumn{2}{c}{\thead{Group}} \\[3ex]
  \turnbox{90}{a} &\multirowthead{-4}[0.3ex]{\rothead{\\[5ex]Long long\\ text}} & A & B \\
  \midrule
  data & data & data & data \\
  \bottomrule
\end{tabular}
\end{document} 

enter image description here