边框表 Latex

边框表 Latex

我使用以下代码在 Latex 中制作了一个表格:

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

该代码给了我下表:

在此处输入图片描述

除顶行外,我的所有单元格都有边框。如何让顶行单元格周围有边框?

答案1

保全脖子的方法:

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

结果

答案2

对于您的表我将使用makecell包:

在此处输入图片描述

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

编辑: 作为 海科·奥伯迪克他在评论中指出,\SI{<angle>}{\degree}packge SI 提供了宏\ang[<options>]{<angle>},这在上述情况下可以缩短代码(请参阅编辑后的代码)。他在自己的回答中展示了这种可能性。

答案3

您尚未透露如何P定义列类型。不过,以下方法应该可行:替换代码块

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

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

相关内容