2

I have this code for a table...

\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}

I wanted to know whether the code for the table can be improved (I'm unfamiliar with LaTeX tables) and also if the part saying 'Design table...' can be displayed nicer and currently it wraps, but it is too much wrapping. Also is there a better way to display the second row content?

enter image description here

5
  • 1
    Welcome to TeX.SX! I used the freedom to do some edits in order your code not to give errors. Added the image too (use the button "image" -with the mountain and the sun- to add images in your post).
    – koleygr
    Commented Jan 19, 2019 at 13:32
  • 2
    The \rotatebox command takes two arguments... The first is the degrees and the second is the text to be rotated... So, your command really works because in your code it is followed by {} that makes latex to give it (informally) the argument that is missing. But someone who will try to use your code without knowing how \rotatebox command has to behave and its syntax, will not really understand the code and will possibly try to use it without the {}.
    – koleygr
    Commented Jan 19, 2019 at 14:01
  • Working on it... Someone else could help too before I finish... Be patient.
    – koleygr
    Commented Jan 19, 2019 at 14:08
  • Writing \multicolumn{3}{|X|}{Design Table for: Coursework Candidate\_Name} is wrong. Consider writing \multicolumn{12}{|l|}{Design Table for: Coursework Candidate\_Name} instead.
    – Mico
    Commented Jan 19, 2019 at 15:10
  • Would transposing the table be an option?
    – leandriis
    Commented Jan 19, 2019 at 15:20

1 Answer 1

3

Here is an answer with the idea of "table notes" to avoid the second row of the table that looks ugly:

\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}

Output:

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .