2

Dear guys on the internet!

i struggle to properly recreate a table from a word document in LaTeX. The following picture shows the goal i want to reach (Screenshot from word document): How the table should look like

I tried it using different packages, but i seem to fail. Here are my tries using tabular package:

\documentclass[paper=a4]{scrartcl}
\usepackage{multirow}

\begin{document}
    \begin{tabular}{|*{15}{c|}}
        \hline
        Weapon Type & S & T.P., cm & $\alpha$, arc minute & H\textsubscript{B}, cm & \multirow{2}{*}{X\textsubscript{B}, cm} & \multicolumn{9}{|c|}{Average Trajectories Height (cm) at Different Distance D} \\[2em]
        & & & & & & 50 & 100 & 150 & 200 & 250 & 300 & 350 & 400 & 500 \\
        \hline
        Weapon & 4 & 18 & 14 & 36 & 207 & 6 & 18 & 26 & 31 & 30 & 25 & 15 & 0 & -47 \\
        %A & B & C & D\\
        \hline
    \end{tabular}
\end{document}

The resulting table looks like this: fail with tabular package

Trying to get linebreaks with the tabularx package also leads to an ugly result:

\documentclass[paper=a4]{scrartcl}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}
    \begin{tabularx}{\textwidth}{|*{6}{X|}c|c|c|c|c|c|c|c|c|}
        \toprule
        Weapon Type & S & T.P., cm & $\alpha$, arc minute & H\textsubscript{B}, cm & \multirow{2}{=}{X\textsubscript{B}, cm} & \multicolumn{9}{X|}{Average Trajectories Height (cm) at Different Distance D} \\
        & & & & & & 50 & 100 & 150 & 200 & 250 & 300 & 350 & 400 & 500 \\
        \midrule
        Weapon & 4 & 18 & 14 & 36 & 207 & 6 & 18 & 26 & 31 & 30 & 25 & 15 & 0 & -47\\
        \bottomrule
    \end{tabularx}
\end{document}

enter image description here

How can i receive a result that is looking like the one i posted in the first image? Why does LaTeX have problems displaying it initially in that way? Can you show me an elegant solution to this problem and give me an explanation? I want to know what i did wrong.

Greetings and thank you for your support!

1 Answer 1

1

Do not use the rules from booktabs if you have vertical lines in your table. Also, you don't really need tabularx here: you can load makecell which allows for line breaks in standard cells. Furthermore it defines the \Xhline and \Xcline commands, which accept a thickness argument, to mimick the variable thickness rules from booktabs. Finally, to prevent the table from overflowing into the margin, I set the intercolumn spacing to 4pt instead of 6.

\documentclass[paper=a4]{scrartcl}
\usepackage{siunitx}
\usepackage{multirow, makecell}
\usepackage{tabularx}

\begin{document}

\setlength{\tabcolsep}{4pt}
\begin{tabular}{!{\vline width 1pt}*{14}{c|}c!{\vline width 1pt}}
    \Xhline{1pt}
    \thead{Weapon \\Type} & S & \thead{T.P.\\ (cm)} & \thead{$\alpha$\\ (\si{\arcmin})} & \thead{H\textsubscript{B}\\ (cm)} & \thead{X\textsubscript{B}\\ (cm)} & \multicolumn{9}{c!{\vline width 1pt}}{\thead{Average Trajectories Height (cm)\\ at Different Distance D}} \\
    \Xcline{7-15}{0.6pt}
    & & & & & & 50 & 100 & 150 & 200 & 250 & 300 & 350 & 400 & 500 \\
    \Xhline{0.6pt}
    Weapon & 4 & 18 & 14 & 36 & 207 & 6 & 18 & 26 & 31 & 30 & 25 & 15 & 0 & $ - $47\\
    \Xhline{1pt}
\end{tabular}

\end{document} 

enter image description here

1
  • Thank you very much @Bernard! You explained it very well and offered a perfect solution. Thank you for your answer! Jan 28, 2020 at 10:18

You must log in to answer this question.

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