2

I made a table in Latex using the following code:

\begin{table}[H]
  \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|}
  \hline
  \multicolumn{1}{P{270}{2cm}}{Distance to target} &
  \multicolumn{1}{P{270}{2cm}}{Angle arrow 1} &
  \multicolumn{1}{P{270}{2cm}}{Angle arrow 2} &
  \multicolumn{1}{P{270}{2cm}}{Angle arrow 3} &
  \multicolumn{1}{P{270}{2cm}}{Angle arrow 4} & 
  \multicolumn{1}{P{270}{2cm}}{Angle arrow 5} & 
  \multicolumn{1}{P{270}{2cm}}{Angle arrow 6} & 
  \multicolumn{1}{P{270}{2cm}}{Average angle} & 
  \multicolumn{1}{P{270}{2.1cm}}{Predicted angle}\\
  \hline
40 & 6$^{\circ}$ & 6$^{\circ}$ & 6$^{\circ}$ & 6$^{\circ}$ & 7$^{\circ}$ & 7$^{\circ}$ & 6.33$^{\circ}$ & 4.67$^{\circ}$ \\ \hline
50 & 8$^{\circ}$ & 8$^{\circ}$ & 9$^{\circ}$ & 8$^{\circ}$ & 9$^{\circ}$ & 8$^{\circ}$ & 8.33$^{\circ}$ & 6.56$^{\circ}$ \\ \hline
60 & 10$^{\circ}$ & 11$^{\circ}$ & 11$^{\circ}$ & 9$^{\circ}$ & 10$^{\circ}$ & 11$^{\circ}$ & 11.33$^{\circ}$ & 7.50$^{\circ}$ \\ \hline
  \end{tabular}
\caption{X}
\label{table1}
\end{table}

This code gave me the following table:

enter image description here

All my cells have a border, except for the top row. How do I get borders around the cells in the top row?

5
  • 3
    Welcome to TeX.SE. Please tell us how the P column type is defined.
    – Mico
    Nov 5, 2016 at 19:57
  • Ik column is rotated 270 degrees and has a length of 2 centimeters
    – Laura
    Nov 5, 2016 at 20:21
  • 1
    I had figured as much. To be able to fully replicate your issue, it's essential though to have the actual code that defines this column type.
    – Mico
    Nov 5, 2016 at 20:23
  • 1
    Welcome to TeX.SX! if you can extend your code to a full minimal working example (MWE) which we can compile to replicate the table you have included as an image. An MWE should begin with \documentclass and end \end{document}.
    – Dai Bowen
    Nov 5, 2016 at 20:43
  • The average angle in the third row is rather 10.33° than 11.33° (the maximum angle is 11°). Nov 5, 2016 at 20:58

3 Answers 3

5

A neck-saving approach:

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
  \begin{tabular}{lccc}
    \toprule
    Distance to target & 40 & 50 & 60 \\
    \addlinespace
    Angle arrow 1 & \ang{6} & \ang{8} & \ang{10}\\
    Angle arrow 2 & \ang{6} & \ang{8} & \ang{11}\\
    Angle arrow 3 & \ang{6} & \ang{9} & \ang{11}\\
    Angle arrow 4 & \ang{6} & \ang{8} & \hphantom{0}\ang{9}\\
    Angle arrow 5 & \ang{7} & \ang{9} & \ang{10}\\
    Angle arrow 6 & \ang{7} & \ang{8} & \ang{11}\\
    \addlinespace
    Average angle & \ang{6.33} & \ang{8.33} & \ang{10.33}\\
    Predicted angle & \ang{4.67} & \ang{6.56} & \hphantom{0}\ang{7.50}\\
    \bottomrule
  \end{tabular}
\end{document}

Result

4

For your table I will use makecell package:

enter image description here

\documentclass{article}
\usepackage{array, makecell, rotating}
\renewcommand\theadfont{\normalsize\bfseries}
\usepackage{siunitx}

\begin{document}
\begin{table}[htb]
    \centering
\settowidth\rotheadsize{\theadfont Predicted angle}
\renewcommand\arraystretch{1.2}
\begin{tabular}{|*{9}{c|} }
    \hline
\rothead{Distance to target}
    &   \rothead{Angle arrow 1}
        &   \rothead{Angle arrow 2}
            &   \rothead{Angle arrow 3}
                &   \rothead{Angle arrow 4}
                    &   \rothead{Angle arrow 5}
                        &   \rothead{Angle arrow 6}
                            &   \rothead{Average angle}
                                &   \rothead{Predicted angle}\\   \hline
40  &   \ang{6}{\degree}
        &   \SI{6}{\degree}
            &   \SI{6}{\degree}
                &   \SI{6}{\degree}
                    &   \SI{7}{\degree}
                        &   \SI{7}{\degree}
                            &   \SI{6.33}{\degree}
                                &   \SI{4.67}{\degree} \\ \hline

50  &   \SI{8}{\degree}
        &   \SI{8}{\degree}
            &   \SI{9}{\degree}
                &   \SI{8}{\degree}
                    &   \SI{9}{\degree}
                        &   \SI{8}{\degree}
                            &   \SI{8.33}{\degree}
                                &   \SI{6.56}{\degree} \\ \hline
60  &   \SI{10}{\degree}
        &   \SI{11}{\degree}
            &   \SI{11}{\degree}
                &   \SI{9}{\degree}
                    &   \SI{10}{\degree}
                        &   \SI{11}{\degree}
                            &   \SI{11.33}{\degree}
                                &   \SI{7.50}{\degree} \\ \hline

  \end{tabular}
\caption{X}
\label{table1}
\end{table}
\end{document}

Edit: As Heiko Oberdiek noted in his comment instead \SI{<angle>}{\degree} packge SI offer macro \ang[<options>]{<angle>}, which in above case enable shorter code (see edited code). This possibilities he show in own answer.

3
  • @Laura, here is habit that your thankfulness express with voting of answer(s) (clicking on upright pen at top left side of answer or even accept it (with clicking on check mark). However, your vote will become visible when you earn enough reputation (I think 15 points). Happy TeX-ing!
    – Zarko
    Nov 5, 2016 at 20:44
  • Package siunitx also offers \ang. Nov 5, 2016 at 20:59
  • @HeikoOberdiek, really? I wasn't aware of it. I must read manual again :-(
    – Zarko
    Nov 5, 2016 at 21:05
1

You haven't revealed how the P column type is defined. Nevertheless, the following approach should work: Replace the code chunk

  \multicolumn{1}{P{270}{2cm}}{Distance to target} &
  \multicolumn{1}{P{270}{2cm}}{Angle arrow 1} &
  \multicolumn{1}{P{270}{2cm}}{Angle arrow 2} &
  \multicolumn{1}{P{270}{2cm}}{Angle arrow 3} &
  \multicolumn{1}{P{270}{2cm}}{Angle arrow 4} & 
  \multicolumn{1}{P{270}{2cm}}{Angle arrow 5} & 
  \multicolumn{1}{P{270}{2cm}}{Angle arrow 6} & 
  \multicolumn{1}{P{270}{2cm}}{Average angle} & 
  \multicolumn{1}{P{270}{2.1cm}}{Predicted angle}\\

with

  \multicolumn{1}{|P{270}{2cm}|}{Distance to target} &
  \multicolumn{1}{P{270}{2cm}|}{Angle arrow 1} &
  \multicolumn{1}{P{270}{2cm}|}{Angle arrow 2} &
  \multicolumn{1}{P{270}{2cm}|}{Angle arrow 3} &
  \multicolumn{1}{P{270}{2cm}|}{Angle arrow 4} & 
  \multicolumn{1}{P{270}{2cm}|}{Angle arrow 5} & 
  \multicolumn{1}{P{270}{2cm}|}{Angle arrow 6} & 
  \multicolumn{1}{P{270}{2cm}|}{Average angle} & 
  \multicolumn{1}{P{270}{2.1cm}|}{Predicted angle}\\

You must log in to answer this question.

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