1

I have the problem, that the cell size on my rotated multirow cells does not adapt its size, so that the contents fit. I tried following the solution described in Long text in rotated multirow , but the cell height is not adapted. This can be seen in the picture

enter image description here

Here is my example:

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{multirow, makecell}
\usepackage{rotating}

\begin{document}
 \begin{table}
  \newcommand{\multirot}[1]{\multirow{2}{*}[1.5ex]{\rotcell{\rlap{#1}}}}
\begin{center}
\caption{Minimal Example Table Problem}
\label{tab:inputVector}
\begin{tabular}{|l|l|l|l|l|l|l|l|l|}
\cline{4-9}
\multicolumn{3}{c|}{} & \multicolumn{6}{c|}{Option}\\
\cline{4-9}
\multicolumn{3}{c|}{} & 
\multirot{Short Name} &
\multirot{Another Name} &
\multirot{A very Long Name} &
\multirot{Longer name} & 
\multirot{Short Name} &
\multirot{Short Name} \\
\cline{1-3}
Method & Column A   & Column B & & & & & &\\
\hline
Method A & AAA & BBB & & & & & &\\
\hline
Method B & AAA & BBB & & & & & &\\
\hline
\end{tabular}
\end{center}
\end{table} 
\end{document}
Thorsten
  • 113
  • You have this command for rotated cells: \settowidth\rotheadsize{\theadfont (Widest head text)} (see p.4 in the documentation). – Bernard Jan 12 '20 at 00:48

2 Answers2

2

Try

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{rotating}
\usepackage{multirow, makecell}

\begin{document} \begin{table} \centering \settowidth\rotheadsize{ very Long Name} \caption{Minimal Example Table Problem} \label{tab:inputVector} \begin{tabular}{|l|l|l|l|l|l|l|l|l|} \cline{4-9} \multicolumn{3}{c|}{} & \multicolumn{6}{c|}{Option}\ \cline{4-9} \multicolumn{3}{c|}{} & & & & & &\ \multicolumn{3}{c|}{} & & & & & &\ \multicolumn{3}{c|}{} & & & & & &\ \multicolumn{3}{c|}{} & & & & & &\ \multicolumn{3}{c|}{} & & & & & &\ \multicolumn{3}{c|}{} & & & & & &\ \cline{1-3} Method & Column A & Column B & \multirow{-6.8}{}{\rothead{Short Name}} & \multirow{-6.8}{}{\rothead{Another Name}} & \multirow{-6.8}{}{\rothead{A very Long Name}} & \multirow{-6.8}{}{\rothead{Longer name}} & \multirow{-6.8}{}{\rothead{Short Name}} & \multirow{-6.8}{}{\rothead{Short Name}} \ \hline Method A & AAA & BBB & & & & & &\ \hline Method B & AAA & BBB & & & & & &\ \hline \end{tabular} \end{table} \end{document}

enter image description here

Addendum: The longest rotated text (A very Long Name) is about 8em long. Knowing this, the second row of table should be 6em high that rotate text can be inside rotated cells (2em is gotten from third row, where multirow cells started and from stretched row highs).

Hight of the second row we can determine by invisible rule \rule{0em}{6em} inserted in the multicolumn cell in this row:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{rotating}
\usepackage{multirow, makecell}
\usepackage[skip=1ex]{caption}  % new

\begin{document} \begin{table} \centering \renewcommand\arraystretch{1.1} \setlength\rotheadsize{8em} \caption{Minimal Example Table Problem} \label{tab:inputVector} \begin{tabular}{|l|l|l|l|l|l|l|l|l|} \cline{4-9} \multicolumn{3}{c|}{} & \multicolumn{6}{c|}{Option}\ \cline{4-9} \multicolumn{3}{c|}{\rule{0em}{6.4em}} & & & & & &\ \cline{1-3} Method & Column A & Column B & \multirow{-7}{}{\rothead{Short Name}} & \multirow{-7}{}{\rothead{Another Name}} & \multirow{-7}{}{\rothead{A very Long Name}} & \multirow{-7}{}{\rothead{Longer name}} & \multirow{-7}{}{\rothead{Short Name}} & \multirow{-7}{}{\rothead{Short Name}} \ \hline Method A & AAA & BBB & & & & & &\ \hline Method B & AAA & BBB & & & & & &\ \hline \end{tabular} \end{table} \end{document}

The result of compilation is a wee bit improved in comparison to the first version of answer:

enter image description here

Zarko
  • 296,517
2

With {NiceTabular} of nicematrix, the following code will do the job (whatever are the contents of the cells).

\documentclass{article}
\usepackage{nicematrix,tikz,caption}

\begin{document} \begin{table} \centering \caption{Minimal Example Table Problem} \label{tab:inputVector} \begin{NiceTabular}{lll|l|l|l|l|l|l|}[cell-space-top-limit=2pt] \cline{4-9} &&& \Block{1-6}{Option} \ \cline{4-9} Method & Column A & Column B & \RowStyle{\rotate} Short Name & Another Name & A Very Long Name & Longer name & Short Name & Short Name \ \hline Method A & AAA & BBB & & & & & &\ \hline Method B & AAA & BBB & & & & & &\ \hline \CodeAfter \tikz \draw (2-1.north-|1) -- (5-|1) (2-1.north-|2) -- (5-|2) (2-1.north-|3) -- (5-|3) (2-1.north-|1) -- (2-1.north-|4) ; \end{NiceTabular} \end{table} \end{document}

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

Output of the above code

F. Pantigny
  • 40,250