我正在尝试构建一个带有两行标题的表格。标题内的文本很长,所以我正在旋转并希望像这样拆分其中一个较长的标题。当前代码生成下图。并且 \newline 命令似乎不起作用
\% 的学生\\学科学校
\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}
答案1
这是一个解决方案makecell
(简化旋转单元格的代码)和\pbox
(工作原理类似\parbox
,除了指定的宽度是 最大限度价值):
\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}