Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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).

share|improve this question

1 Answer 1

up vote 6 down vote accepted
  • 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}
share|improve this answer
    
I am using \multirow{4}{*}{...} only where I need it (see Fig. 2). I know it works without the height adjustment, but I need it. I did not know about the fixup argument, though. I shall try it and then report. However, this is still not a solution as I need the column to rotate the content automatically. –  Harold Cavendish Jul 31 '11 at 13:45
    
@Harrold: I see, corrected. Just Fig. 1 led me to think there were 2 rows to span. –  Stefan Kottwitz Jul 31 '11 at 14:17
    
It is not exactly what I hoped for but certainly useful for situations without the need to adjust the height of columns, thank you. –  Harold Cavendish Jul 31 '11 at 16:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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