如何将列标题分成两行?

如何将列标题分成两行?
\documentclass[12pt,a4paper]{book} 
\usepackage{array} 
\begin{document}
\begin{table}[H]
\setlength{\tabcolsep}{5mm}
\begin{tabular}[h]{|>{\centering\arraybackslash}p{2cm}||>      {\centering\arraybackslash}p{3cm}|>{\centering\arraybackslash}p{2cm}|>{\centering\arraybackslash}p{1cm}|>{\centering\arraybackslash}p{2.5cm}|} 
\hline
\rotatebox{90} {\centering case1}      & \rotatebox{90}{\centering Case2}   &  \rotatebox{90}{\centering This is the case 3?} & \rotatebox{90} {\centering Case 4}  \\ \hline\hline
a      &  b    & c  & d  \\ \hline 
\end{tabular}
\caption{My table}
\end{table}
\end{document}

我怎样才能将标题“这是案件3”分成两行?

答案1

一种方法是使用类似

\parbox{2cm}{\raggedright This is the case 3?}

或者添加\\以手动分割线:

\parbox{2cm}{\raggedright This is \\ the case 3?}

在此处输入图片描述

代码:

\documentclass{article}
\usepackage{array}
\usepackage{graphicx}
\begin{document}
\setlength{\tabcolsep}{5mm}
\begin{tabular}[h]{|>{\centering\arraybackslash}p{2cm}||>      {\centering\arraybackslash}p{3cm}|>{\centering\arraybackslash}p{2cm}|>{\centering\arraybackslash}p{1cm}|>{\centering\arraybackslash}p{2.5cm}|} 
\hline
\rotatebox{90} {\centering case1}      & \rotatebox{90}{\centering Case2}   &  
\rotatebox{90}{\centering \parbox{2cm}{\raggedright This is the case 3?}} & \rotatebox{90} {\centering Case 4}  \\ \hline\hline
a      &  b    & c  & d  \\ \hline 
\end{tabular}

\begin{tabular}[h]{|>{\centering\arraybackslash}p{2cm}||>      {\centering\arraybackslash}p{3cm}|>{\centering\arraybackslash}p{2cm}|>{\centering\arraybackslash}p{1cm}|>{\centering\arraybackslash}p{2.5cm}|} 
\hline
\rotatebox{90} {\centering case1}      & \rotatebox{90}{\centering Case2}   &  
\rotatebox{90}{\centering \parbox{2cm}{\raggedright This is \\ the case 3?}} & \rotatebox{90} {\centering Case 4}  \\ \hline\hline
a      &  b    & c  & d  \\ \hline 
\end{tabular}
\end{document}

答案2

\centering

 \rotatebox{90}{\centering This is the case 3?}

什么都不做,就像

 \mbox{\centering This is the case 3?}

在两种情况下,都有一个 TeX 水平(LR)框,其中不会发生换行。

根据您想要的外观,以下任何一种工作都会产生不同的效果


\rotatebox{90}{\parbox{2cm}{\centering This is the\\ case 3?}}

\rotatebox{90}{\parbox{2cm}{This is the\\ case 3?}}

\rotatebox{90}{This is the}
\rotatebox{90}{case 3?}}

相关内容