2

I am trying to make the table with automatically centered, rotated multirow cells. Something like in the picture, but with cells automatically fitted to their content:

enter image description here

I tried to apply solutions given by @AboAmmar and @Seong, but these not ensure vertical centering within the specified number of rows. This answer is unclear, because \multirow command under makecell package accepts non-integer value of number of rows (?). Here is given some code, but the problem is that this engages fixed value (in \raisebox argument) which is proper only for one specific cell content. The most similar question is without answer.

In fact I need some function which should be named \multirowrothead - as a combination of \multirowthead and \rothead functions of the makecell package. My code:

\documentclass[table]{standalone}
\usepackage{siunitx}
\usepackage{makecell}
\usepackage{xcolor}
\usepackage{multirow}
\usepackage{hhline}
\renewcommand{\theadfont}{\normalsize\bfseries}
\renewcommand{\arraystretch}{1.3}

\begin{document}
    \begin{tabular}{
        |l|
        S[table-format=2.1]|
        S[table-format=1.2]|
        S[table-format=2.1]|
        S[table-format=1.2]|
        S[table-format=2.1]|
        S[table-format=1.2]|
    }
        \hline
        % https://tex.stackexchange.com/questions/246889/how-to-color-column-heads-determined-width-makecell
        \rowcolor{gray}
        \multicolumn{3}{|c|}{\colorbox{gray}{\thead{First title in heading}}} &
        \multicolumn{2}{c|}{\colorbox{gray}{\thead{Second title\\in heading}}} & &\\
        \hhline{>{\arrayrulecolor{black}}|-----|>{\arrayrulecolor{gray}}-%
            >{\arrayrulecolor{black}}|>{\arrayrulecolor{gray}}->{\arrayrulecolor{black}}|%
        }
        \rowcolor{gray}
        & & & & \colorbox{gray}{\thead{data\\description}} &
        {\multirowthead{-2}{Data\\description}} &\\
        \hhline{%
            >{\arrayrulecolor{black}}|>{\arrayrulecolor{gray}}-%
            >{\arrayrulecolor{black}}|>{\arrayrulecolor{gray}}-%
            >{\arrayrulecolor{black}}|>{\arrayrulecolor{gray}}-%
            >{\arrayrulecolor{black}}|>{\arrayrulecolor{gray}}-%
            >{\arrayrulecolor{black}}|-|-|%
            >{\arrayrulecolor{gray}}->{\arrayrulecolor{black}}|%
        }
        \rowcolor{gray}
        \colorbox{gray}{\multirowthead{-2}{side-heading\\description}} &
        \colorbox{gray}{\multirowthead{-2}{data\\description}} &
        \colorbox{gray}{\multirowthead{-2}{data\\description}} &
        \colorbox{gray}{\multirowthead{-2}{data\\description}} &
        \colorbox{gray}{\thead{A}} & \colorbox{gray}{\thead{B}} &
        \colorbox{gray}{\multirowthead{-3}{Data description}}\\
        \hline
        Description 1 & 63.5 & 4.87 & 63.5 & 4.87 & 63.5 & 4.87\\
        \hline
        Description 2 & 88.4 & 5.13 & 88.4 & 5.13 & 88.4 & 5.13\\
        \hline
    \end{tabular}
\end{document}
1
  • 2
    if you make the value of a smaller how will the word Description fit in the first row – js bibra Sep 16 '20 at 5:06
3

You can't have the quantity b in green on your picture smaller because the (total) height of the rows 2 and 3 is constrained by the contents of the cells of the column 5.

Here is what you can do with {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{siunitx}
\renewcommand{\arraystretch}{1.3}

\usepackage{nicematrix}

\begin{document}
\begin{NiceTabular}[ hvlines , code-before = \rowcolor{gray!30}{1-3} ]   
    {
        c
        S[table-format=2.1]
        S[table-format=1.2]
        S[table-format=2.1]
        S[table-format=1.2]
        S[table-format=2.1]
        S[table-format=1.2]
    }%
{\Block{1-3}{First title in heading}} & & & 
  \Block{1-2}{Second title\\in heading} & &
{\Block{2-1}<\rotate>{Data\\description}} &  
{\Block{3-1}<\rotate>{Data description}} \\
  {\Block{2-1}<\rotate>{side-heading\\description}}
& {\Block{2-1}<\rotate>{data\\description}}
& {\Block{2-1}<\rotate>{data\\description}}
& {\Block{2-1}<\rotate>{data\\description}}
& \Block{}<\rotate>{data\\description\hspace*{0.5em}} \\
& & & & {A} & {B} \\
Description 1 & 63.5 & 4.87 & 63.5 & 4.87 & 63.5 & 4.87\\
Description 2 & 88.4 & 5.13 & 88.4 & 5.13 & 88.4 & 5.13\\
\end{NiceTabular}
\end{document} 
  • In {NiceTabular}, you merge cells both vertically and horizontally with the built-in command \Block.

  • With the key hvlines, you draw all the rules excepted in the blocks (which is what is expected here).

  • The built-in command \rotate is used to rotate contents of cells and blocks.

  • You can color cells, rows and columns with commands in the key code-before (however, it's also possible to use a syntax similar to the syntax of colortbl). Usually, the output is good in all PDF viewers at all levels of zoom.

  • However, you need several compilations.

Output of the above code

2
  • About dimension b - you are right. I have a problem with compilation. Firstly environment NiceTabular was not recognized - similar problem as here. But after execution latex nicematrix.ins on new nicematrix.ins nad nicematrix.dtx files I met new problem by compilation of the file with the exemplary table: ! LaTeX error: "xparse/unknown-argument-type" ! ! Unknown argument type 'b' for the command '\environment ! __nicematrix-light-syntax'. – forrest Sep 16 '20 at 7:28
  • For that problem, it will be easier to reply by email. Send me your log file: fpantigny@wanadoo.fr – F. Pantigny Sep 16 '20 at 9:29

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.