如何格式化具有多列和 \cline 的书本样式的表格?

如何格式化具有多列和 \cline 的书本样式的表格?

我读了很多类似的问题,但没有一个适合我的情况。我需要一个有 2 个多列的表格。

这是我的代码:

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


\begin{document}

\begin{table}[]
\centering
\caption{}
\label{tab:my-table}
\begin{tabular}{
c
S[round-mode=places,round-precision=3] %col4
S[round-mode=places,round-precision=3,scientific-notation = true] %col4
S[round-mode=places,round-precision=2] %col4
S[round-mode=places,round-precision=2,scientific-notation = true] %col4
}
\toprule
\textbf{Lagrange\_point} & \multicolumn{2}{l}{\textbf{\begin{tabular}[c]{@{}l@{}}x- coordinate \\ (au) \hspace{1cm}   (km)\end{tabular}}} & \multicolumn{2}{l}{\textbf{\begin{tabular}[c]{@{}l@{}}y- coordinate \\ (au) \hspace{1cm}  (km)\end{tabular}}} \\ \midrule
1 & -0.98998598231694 & -148099794.977462 & 0 & 0 \\
2 & -1.0100752000489 & -151105099.174192 & 0 & 0 \\
3 & 1.00000126684309 & 149598060.217029 & 0 & 0 \\
4 & -0.499996959576574 & -74798480.5091294 & 0.866025403784439 & 129555556.37826 \\
5 & -0.499996959576574 & -74798480.5091294 & -0.866025403784439 & -129555556.37826 \\ \bottomrule
\end{tabular}
\end{table}


\end{document}

结果如下(我插入了红线来给出要分组的列的概念): 在此处输入图片描述

答案1

booktabs还提供了\cmidrule[](){}仅绘制水平线的一部分的功能。在下面的解决方案中,我将多个 改为tabular一个\multirow{}*{},这稍微简化了代码。此外,请考虑将其table-format作为选项添加到S-type 列中。

我个人会移动中间有间隙的水平线,所以这里有两个版本的表格

在此处输入图片描述

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

\sisetup{
    round-mode=places,
    uncertainty-mode = separate,
}

\begin{document}
\begin{table}[tbh]
    \centering
    \caption{}
    \label{tab:my-table}
    \begin{tabular}{
    >{\centering\arraybackslash}p{1.75cm}
    S[table-format=-1.3, round-precision=3] %col4
    S[table-format=-1.3e1, round-precision=3, scientific-notation = true] %col4
    S[table-format=-1.2, round-precision=2] %col4
    S[table-format=-1.2e1, round-precision=2, scientific-notation = true] %col4
    }
    \toprule
    \textbf{Lagrange}
    & \multicolumn{2}{l}{\textbf{x- coordinate}}
    & \multicolumn{2}{l}{\textbf{y- coordinate}} \\
    \textbf{point}
    & \phantom{$-$}\textbf{(au)}
    & \textbf{(km)}
    & \phantom{$-$}\textbf{(au)}
    & \textbf{(km)} \\
    \cmidrule(r){1-1} \cmidrule(lr){2-3} \cmidrule(l){4-5}
    1 & -0.98998598231694 & -148099794.977462 & 0 & 0 \\
    2 & -1.0100752000489 & -151105099.174192 & 0 & 0 \\
    3 & 1.00000126684309 & 149598060.217029 & 0 & 0 \\
    4 & -0.499996959576574 & -74798480.5091294 & 0.866025403784439 & 129555556.37826 \\
    5 & -0.499996959576574 & -74798480.5091294 & -0.866025403784439 & -129555556.37826 \\ \bottomrule
    \end{tabular}
\end{table}

\begin{table}[tbh]
    \centering
    \caption{}
    \label{tab:my-table11}
    \begin{tabular}{
    c
    S[table-format=-1.3, round-precision=3] %col4
    S[table-format=-1.3e1, round-precision=3, scientific-notation = true] %col4
    S[table-format=-1.2, round-precision=2] %col4
    S[table-format=-1.2e1, round-precision=2, scientific-notation = true] %col4
    }
    \toprule
    \multirow{2}*[-2pt]{\textbf{\parbox{1.75cm}{\centering Lagrange\\point}}}
    & \multicolumn{2}{c}{\textbf{x- coordinate}}
    & \multicolumn{2}{c}{\textbf{y- coordinate}} \\
    \cmidrule(lr){2-3} \cmidrule(l){4-5}
    & \phantom{$-$}\textbf{(au)}
    & \textbf{(km)}
    & \phantom{$-$}\textbf{(au)}
    & \textbf{(km)} \\
    \midrule
    1 & -0.98998598231694 & -148099794.977462 & 0 & 0 \\
    2 & -1.0100752000489 & -151105099.174192 & 0 & 0 \\
    3 & 1.00000126684309 & 149598060.217029 & 0 & 0 \\
    4 & -0.499996959576574 & -74798480.5091294 & 0.866025403784439 & 129555556.37826 \\
    5 & -0.499996959576574 & -74798480.5091294 & -0.866025403784439 & -129555556.37826 \\ \bottomrule
    \end{tabular}
\end{table}
\end{document}

相关内容