更好地显示表格并改善代码

更好地显示表格并改善代码

我有一张表的这个代码......

\documentclass[11pt,a4paper]{article}
\usepackage[margin=20mm]{geometry}
\usepackage{rotating}
\usepackage{float}
\newcommand*\rot[1]{\rotatebox{90}{#1}}
\usepackage{tabularx}
\renewcommand{\arraystretch}{1.5}
\begin{document}
\begin{table}[H]
  \begin{tabularx}{\textwidth}{|XXXXXXXXXXXX|}
  \hline
  \multicolumn{3}{|X|}{Design Table for: Coursework Candidate\_Name} &  &  &  &  &  &  &  &  &  \\
  \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
  \multicolumn{1}{|l|}{} & \multicolumn{1}{l|}{\rot{D1@Sketch4}} & \multicolumn{1}{l|}{} & 
  \multicolumn{1}{l|}{\rot{D1@Sketch1}} & \multicolumn{1}{l|}{\rot{D1@Boss-Extrude1}} & 
  \multicolumn{1}{l|}{\rot{D1@Sketch2}} & \multicolumn{1}{l|}{\rot{D1@Boss-Extrude2}} & 
  \multicolumn{1}{l|}{\rot{D1@Sketch3}} & \multicolumn{1}{l|}{\rot{D2@Sketch3}} & \multicolumn{1}{l|}{\rot{D3@Sketch3}} & \multicolumn{1}{l|}{\rot{D2@Sketch4}} & \multicolumn{1}{l|}{\rot{D3@Sketch4}} \\
  \hline
  \multicolumn{1}{|l|}{Default} & \multicolumn{1}{l|}{55} & \multicolumn{1}{l|}{240} & \multicolumn{1}{l|}{220} & \multicolumn{1}{l|}{27.5} & \multicolumn{1}{l|}{110} & \multicolumn{1}{l|}{27.5} & \multicolumn{1}{l|}{82.5} & \multicolumn{1}{l|}{9} & \multicolumn{1}{l|}{20} & \multicolumn{1}{l|}{6.875} & \multicolumn{1}{l|}{13.75} \\
  \hline
  \multicolumn{1}{|l|}{132M} & \multicolumn{1}{l|}{55} & \multicolumn{1}{l|}{240} & \multicolumn{1}{l|}{220} & \multicolumn{1}{l|}{27.5} & \multicolumn{1}{l|}{110} & \multicolumn{1}{l|}{27.5} & \multicolumn{1}{l|}{82.5} & \multicolumn{1}{l|}{9} & \multicolumn{1}{l|}{20} & \multicolumn{1}{l|}{6.875} & \multicolumn{1}{l|}{13.75} \\
  \hline
  \multicolumn{1}{|l|}{100L} & \multicolumn{1}{l|}{38} & \multicolumn{1}{l|}{135} & \multicolumn{1}{l|}{152} & \multicolumn{1}{l|}{19} & \multicolumn{1}{l|}{76} & \multicolumn{1}{l|}{19} & \multicolumn{1}{l|}{57} & \multicolumn{1}{l|}{6} & \multicolumn{1}{l|}{20} & \multicolumn{1}{l|}{4.75} & \multicolumn{1}{l|}{9.5} \\
  \hline
  \multicolumn{1}{|l|}{80L} & \multicolumn{1}{l|}{24} & \multicolumn{1}{l|}{24} & \multicolumn{1}{l|}{96} & \multicolumn{1}{l|}{12} & \multicolumn{1}{l|}{48} & \multicolumn{1}{l|}{12} & \multicolumn{1}{l|}{36} & \multicolumn{1}{l|}{6} & \multicolumn{1}{l|}{8} & \multicolumn{1}{l|}{3} & \multicolumn{1}{l|}{6} \\
  \hline
  \multicolumn{1}{|l|}{63S} & \multicolumn{1}{l|}{11} & \multicolumn{1}{l|}{10} & \multicolumn{1}{l|}{44} & \multicolumn{1}{l|}{5.5} & \multicolumn{1}{l|}{22} & \multicolumn{1}{l|}{5.5} & \multicolumn{1}{l|}{16.5} & \multicolumn{1}{l|}{3} & \multicolumn{1}{l|}{8} & \multicolumn{1}{l|}{1.375} & \multicolumn{1}{l|}{2.75} \\
  \hline
  \end{tabularx}
\end{table}
\end{document}

我想知道是否可以改进表格的代码(我不熟悉 LaTeX 表格),以及“设计表格...”部分是否可以显示得更好,目前它是换行的,但换行太多了。还有没有更好的方法来显示第二行的内容?

在此处输入图片描述

答案1

以下是一个使用“表格注释”思想的答案,以避免表格第二行看起来很丑陋:

\documentclass[11pt,a4paper]{article}
\usepackage[margin=20mm]{geometry}
\usepackage{float}
\usepackage{rotating}
\usepackage{siunitx}
\newcommand*\rot[1]{\rotatebox{90}{#1}}
\def\fnsymbol#1{\ensuremath{\ifcase#1\or *\or \dagger\or \ddagger\or
   \mathsection\or \mathparagraph\or \|\or **\or \dagger\dagger
   \or \ddagger\ddagger \else\@ctrerr\fi}}
%\usepackage{tabularx}
\renewcommand{\arraystretch}{1.5}
\begin{document}
\begin{table}[H]
  \begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}|c|S[table-format=2]|S[table-format=3]|S[table-format=3]|S[table-format=2.1]|S[table-format=3]||S[table-format=2.1]|S[table-format=2.1]|S[table-format=1]|S[table-format=2]|S[table-format=1.3]|S[table-format=2.2]|}
  \hline
  \multicolumn{3}{|c|}{\begin{tabular}{c}Design Table for:\\ Coursework Candidate\_Name\end{tabular}} &\multicolumn{9}{c|}{} \\
  \hline
   & \rot{Shaft Diameter} & \rot{Max Torque} & 
  \rot{Outer Flange Diameter} & \rot{Flange Base Depth} & \rot{Inner Flange Diameter} & \rot{Flange Boss Depth} & \rot{Pitch Centre Diameter} & \rot{Number of Holes} & \rot{Hole Diameter} & \rot{Key Way Width} & \rot{Key Way Depth} \\
  \hline
  & $\fnsymbol{1}$&  & 
  $\fnsymbol{2}$ & $\fnsymbol{3}$ & 
  $\fnsymbol{4}$ & $\fnsymbol{5}$ & 
  $\fnsymbol{6}$ & $\fnsymbol{6}$& $\fnsymbol{6}$ & $\fnsymbol{7}$ & $\fnsymbol{7}$ \\
  \hline
  Default & 55 & 240 & 220 & 27.5 & 110 & 27.5 & 82.5 & 9 & 20 & 6.875 & 13.75 \\
  \hline
  132M & 55 & 240 & 220 & 27.5 & 110 & 27.5 & 82.5 & 9 & 20 & 6.875 & 13.75 \\
  \hline
  100L & 38 & 135 & 152 & 19 & 76 & 19 & 57 & 6 & 20 & 4.75 & 9.5 \\
  \hline
  80L & 4 & 24 & 96 & 12 & 48 & 12 & 36& 6 & 8 & 3 & 6 \\
  \hline
  63S & 11 & 10& 44& 5.5 & 22 & 5.5 & 16.5 & 3 & 8 & 1.375 & 2.75 \\\hline
  \multicolumn{12}{|c|}{\begin{tabular}{@{}llll@{}}$\fnsymbol{1}$: D1@Sketch4 & $\fnsymbol{2}$: D1@Sketch1& $\fnsymbol{3}$: D1@Boss-Extrude1 & $\fnsymbol{4}$: D1@Sketch2 \\$\fnsymbol{5}$: D1@Boss-Extrude2 & $\fnsymbol{6}$: D1@Sketch3 & $\fnsymbol{7}$: D3@Sketch4& \end{tabular}}\\
  \hline
  \end{tabular*}
\end{table}

Test text here with length at least one full line in order to see if table takes over all the line width and goes to next line
\end{document}

输出:

在此处输入图片描述

相关内容