1

I'm trying to build a table with a two row header. The text within the header is long so I'm rotating and hoping to split one of the longer headers like so. The current code produces the picture below. and the \newline command doesn't appear to work

\% of students in \\ subject schools

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{array}
\usepackage{float}
\usepackage{rotating}
\usepackage{longtable}    
\usepackage{xcolor}

\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}

\begin{document}

\section{Introduction}
\begin{longtable}{R{0.3in}|R{0.4in}R{0.3in}|R{0.4in}R{0.2in}R{0.3in}R{0.4in}|R{0.3in}R{0.2in}R{0.4in}R{0.3in}}
\caption{GCSE uptake} \\ 
  \hline
  & \multicolumn{2}{c}{Population} & \multicolumn{4}{c}{Subject reach} & \multicolumn{4}{c}{Subject actual} \\\
 \begin{sideways}Region\end{sideways} & \begin{sideways}Schools\end{sideways} & \begin{sideways}Students\end{sideways} & \begin{sideways}Schools\end{sideways} & \begin{sideways}Students\end{sideways} & \begin{sideways}per of all schools\end{sideways} & \begin{sideways}\% of all students\end{sideways} & \begin{sideways}Students\end{sideways} &  \begin{sideways}\% of students in \newline subject schools\end{sideways} &  \begin{sideways}\% of all students\end{sideways} & \begin{sideways}Avg Cohort\end{sideways} \\
 \hline
North West & 627 & 75103 & 405 & 62382 & 65 & 83.1 & 9873 & 13.1 & 15.8 & 24.4 \\ 
  East of England & 498 & 64314 & 323 & 52760 & 65 & 82.0 & 8211 & 12.8 & 15.6 & 25.4 \\ 
\hline
\end{longtable}

\end{document}

enter image description here

2

Here is a solution with makecell (to simplify the code for rotated cells) and \pbox (works like \parbox, except the specified width is a maximum value):

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{array}
\usepackage{float}
\usepackage{rotating}
\usepackage{longtable}
\usepackage{makecell}
\renewcommand{\theadfont}{\normalsize}
\usepackage{pbox}
\usepackage{setspace}
\usepackage{xcolor}

\newcolumntype{R}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}

\section{Introduction}
\setlength{\rotheadsize}{1.1in}
\setlength{\extrarowheight}{2pt}
    \begin{longtable}{l|R{0.4in}R{0.3in}|R{0.4in}R{0.2in}R{0.3in}R{0.4in}|R{0.3in}R{0.2in}R{0.4in}R{0.3in}}
    \caption{GCSE uptake} \\
      \hline
      & \multicolumn{2}{c}{Population} & \multicolumn{4}{c}{Subject reach} & \multicolumn{4}{c}{Subject actual} \\%
    \thead[lb]{ Region} & \rothead{Schools} & \rothead{Students} & \rothead{Schools} & \rothead{Students} & \rothead{per of all schools} & 
    \rothead{\% of all students} & \rothead{Students} &\rothead{\smash{\pbox{\rotheadsize}{\setstretch{0.8}\raggedright \% of students \newline in subject schools }}}    
     & \rothead{\% of all students} & \rothead{Avg Cohort} \\
     \hline
    North West & 627 & 75103 & 405 & 62382 & 65 & 83.1 & 9873 & 13.1 & 15.8 & 24.4 \\
      East of England & 498 & 64314 & 323 & 52760 & 65 & 82.0 & 8211 & 12.8 & 15.6 & 25.4 \\
    \hline
    \end{longtable}

\end{document}

enter image description here

2
  • just checking, you have to use rothead for this? – pluke Jun 27 '19 at 15:18
  • 1
    It's not absolutely necessary – it mainly simplifies the code, as it automatically turns by 90° counterclock wise by default. Also loading makecell can be useful for several other purposes. – Bernard Jun 27 '19 at 15:24

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.