[Tex/LaTex] Producing a column with rotated text in all cells

rotatingtablestabularx

I would like to set the first and the second column of the shown tabularx table to automatically rotate any text inside a single cell of one row or a single cell consisting of cells joined by \multirow and to center it both vertically and horizontally while allowing to adjust the height of the columns by \\[height] or other method with top vertical alignment of the content.

Just to explain the rule through the first column, I also need \noalign{\hrule height 1pt} to behave like \cline{2-4}, hence not affecting the first column, but that is for another question, I guess.

Minimal working example:

\documentclass[11pt, a4paper]{article}
\usepackage{lmodern}
\usepackage{array}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{tabularx}
\begin{document}

\scriptsize
\setlength{\extrarowheight}{0.2em}
\noindent\begin{tabularx}{\textwidth}{!{\vrule width 1pt} p{0.3cm} !{\vrule width 1pt} p{0.5cm} | p{4cm} | X !{\vrule width 1pt}}
\noalign{\hrule height 1pt}
\multirow{4}{*}{\rotatebox{90}{Ten}}&\multirow{2}{*}{\rotatebox{90}{Eight}} & One & Two\\[0.5cm] \cline{3-4}
& & Three & Four\\[1cm] \noalign{\hrule height 1pt}
&\multirow{2}{*}{\rotatebox{90}{Nine}} & Five & Six\\[0.5cm] \cline{3-4}
& & \multicolumn{2}{ l !{\vrule width 1pt}}{Seven}\\[1cm]
\noalign{\hrule height 1pt}
\end{tabularx}

\end{document}

The current state.

Fig. 1: The current state.

The objective.

Fig. 2: The approximate objective (digitally manipulated in a graphics editing program).

Best Answer

  • You could use an option for customizing the origin of the rotation, such as \rotatebox[origin=c]{90}{...}

  • The manually added vertical space at the end of the rows destroys the aligment. see how it looks without:

    \documentclass[11pt, a4paper]{article}
    \usepackage{lmodern}
    \usepackage{array}
    \usepackage{graphicx}
    \usepackage{multirow}
    \usepackage{tabularx}
    \begin{document}
    
    \scriptsize
    \setlength{\extrarowheight}{0.2em}
    \noindent\begin{tabularx}{\textwidth}{!{\vrule width 1pt}
        p{0.3cm} !{\vrule width 1pt} p{0.5cm} | p{4cm} | X !{\vrule
        width 1pt}}
    \noalign{\hrule height 1pt}
    \multirow{4}{*}{\rotatebox[origin=c]{90}{Ten}}&
        \multirow{2}{*}{\rotatebox[origin=c]{90}{Eight}}
        & One & Two\\\cline{3-4}
    & & Three & Four\\\cline{2-4}
    &\multirow{2}{*}{\rotatebox[origin=c]{90}{Nine}}
    & Five & Six\\ \cline{3-4}
    & & \multicolumn{2}{ l !{\vrule width 1pt}}{Seven}\\
    \noalign{\hrule height 1pt}
    \end{tabularx}
    
    \end{document}
    

enter image description here

  • If you make such manual adjustments, which multirow doesn't know about, you can use the optional fixup argument of \multirow for correction:

    \multirow{nrows}[bigstruts]{width}[fixup]{text}
    
  • For automatic rotating, I would use >{...} and >{...} of the array package together with a sideways environment of the rotating package, such as

    >{\begin{sideways}}p{0.3cm}<{\end{sideways}}
    

or even define a new column type for it:

\newcolumntype{R}[1]{>{\begin{sideways}}p{#1}<{\end{sideways}}}

Here's the example showing automatic rotation, but without multirow, since this would not work as intended as it's applied after rotation:

\documentclass[11pt, a4paper]{article}
\usepackage{lmodern}
\usepackage{array}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{rotating}
\newcolumntype{R}[1]{>{\begin{sideways}}p{#1}<{\end{sideways}}}
\begin{document}
\scriptsize
\setlength{\extrarowheight}{0.2em}
\noindent\begin{tabularx}{\textwidth}{!{\vrule width 1pt}
    R{0.3cm} !{\vrule width 1pt} R{0.5cm} | p{4cm} | X !{\vrule
    width 1pt}}
\noalign{\hrule height 1pt}
Ten & Eight
& One & Two\\\cline{3-4}
& & Three & Four\\\cline{2-4}
& Nine
& Five & Six\\ \cline{3-4}
& & \multicolumn{2}{ l !{\vrule width 1pt}}{Seven}\\
\noalign{\hrule height 1pt}
\end{tabularx}
\end{document}
Related Question