我有这段代码,它是一个大表的开始部分。
\begin{table}[H]
\begin{tabularx}{\textwidth}{XXXXXXXXXXXX}
\hline
\multicolumn{1}{|X|}{} & \multicolumn{1}{X|}{Shaft Diameter} & \multicolumn{1}{X|}{Max Torque} &
\multicolumn{1}{X|}{Outer Flange Diameter} & \multicolumn{1}{X|}{Flange Base Depth} & \multicolumn{1}{X|}{Inner Flange Diameter} & \multicolumn{1}{X|}{Flange Boss Depth} & \multicolumn{1}{X|}{Pitch Centre Diameter} & \multicolumn{1}{X|}{Number of Holes} & \multicolumn{1}{X|}{Hole Diameter} & \multicolumn{1}{X|}{Key Way Width} & \multicolumn{1}{X|}{Key Way Depth} \\
\hline
但是,即使标题换行了,显示效果也不太好。有什么办法可以解决这个问题吗?
答案1
您无法在如此狭窄的栏目中容纳这些长标题。使用连字符连接它们并不是解决方案,因为它们变得完全不可读。
你可能旋转标题并使其变小,但这只是“最后的手段”。
\documentclass{article}
\usepackage{tabularx,graphicx}
\newcommand{\mh}[1]{%
\multicolumn{1}{c|}{%
\makebox[0pt]{%
\rotatebox[origin=cl]{90}{%
\footnotesize\begin{tabular}{@{}l}#1\end{tabular}%
}%
}%
}%
}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{|X|*{11}{>{\raggedleft\arraybackslash}X|}}
\hline
& \mh{Shaft Diameter} & \mh{Max Torque} &
\mh{Outer Flange \\ Diameter} & \mh{Flange Base \\ Depth} &
\mh{Inner Flange \\ Diameter} & \mh{Flange Boss \\ Depth} &
\mh{Pitch Centre \\ Diameter} & \mh{Number of Holes} &
\mh{Hole Diameter} & \mh{Key Way Width} & \mh{Key Way Depth} \\
\hline
a & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 \\
\hline
\end{tabularx}
\end{document}
不过,我会选择“索引”格式。
\documentclass{article}
\usepackage{tabularx,booktabs}
\newcommand{\mh}[1]{\multicolumn{1}{c}{(#1)}}
\newcommand{\mhd}[2]{\mbox{(#1): #2}}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{X*{11}{>{\raggedleft\arraybackslash}X}}
\toprule
& \mh{1} & \mh{2} & \mh{3} & \mh{4} & \mh{5} & \mh{6}
& \mh{7} & \mh{8} & \mh{9} & \mh{10} & \mh{11} \\
\midrule
a & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 \\
a & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 \\
a & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 \\
\bottomrule
\end{tabularx}
\medskip
{\footnotesize\raggedright
\mhd{1}{Shaft Diameter};
\mhd{2}{Max Torque};
\mhd{3}{Outer Flange Diameter};
\mhd{4}{Flange Base Depth};
\mhd{5}{Inner Flange Diameter};
\mhd{6}{Flange Boss Depth};
\mhd{7}{Pitch Centre Diameter};
\mhd{8}{Number of Holes};
\mhd{9}{Hole Diameter};
\mhd{10}{Key Way Width};
\mhd{11}{Key Way Depth}.\\}
\end{document}
答案2
鉴于该表有一个标题列和 11 个 [11!] 数据列,几乎肯定需要以以下格式排版该表横向格式. 一种方法是使用包sidewaystable
提供的环境rotating
,而不是table
环境。
请注意,如果您使用X
数据列的列类型,则无需将标题单元格包裹在\multicolumn{1}{X|}{...}
“包装器”中。
\documentclass{article} % choose an appropriate document class
\usepackage[a4paper,margin=2.5cm]{geometry} % select suitable page parameters
\usepackage[english]{babel} % load language-appropriate hyphenation patterns
\usepackage{rotating} % for 'sidewaystable' env.
\usepackage{tabularx} % for 'tabularx' env. and 'X' col. type
\usepackage{ragged2e} % for '\Centering' macro
\newcolumntype{C}{>{\Centering\arraybackslash\hspace{0pt}}X}
\begin{document}
\begin{sidewaystable}
\setlength\tabcolsep{3pt} % default: 6pt
\setlength\extrarowheight{2pt} % for a slightly more open "look"
\begin{tabularx}{\textwidth}{|*{12}{C|}}
\hline
& Shaft Diameter &
Max Torque & Outer Flange Diameter &
Flange Base Depth & Inner Flange Diameter &
Flange Boss Depth & Pitch Centre Diameter &
Number of Holes & Hole Diameter &
Key Way Width & Key Way Depth \\
\hline
\end{tabularx}
\end{sidewaystable}
\end{document}