\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{ c|c|c|c|c}
& \multicolumn{2}{c}{Verbal} & \multicolumn{2}{c}{Math} \\
\hline
L & $\kappa\left(A^TA\right)$ & $2010$ & $\kappa\left(A^TA\right)$ & $2010$ \\
\hline
1 & $\num{1.000e+00}$ & $\num{1.000e+00}$ & $\num{5.466e+02}$ & $\num{5.498e+02}$\\
2 & $\num{9.797e+11}$ & $\num{9.797e+11}$ & $\num{-1.874e+03}$ & $\num{-3.596e+02}$\\
3 & $\num{4.728e+22}$ & $\num{4.728e+22}$ & $\num{7.069e+04}$ & $\num{4.039e+05}$\\
4 & $\num{1.460e+27}$ & $\num{1.460e+27}$ & $\num{-2.279e+07}$ & $\num{-2.732e+08}$\\
5 & $\num{4.128e+32}$ & $\num{4.128e+32}$ & $\num{5.379e+10}$ & $\num{1.473e+10}$\\
6 & $\num{3.250e+40}$ & $\num{3.250e+40}$ & $\num{-1.329e+13}$ & $\num{2.339e+13}$\\
7 & $\num{7.321e+46}$ & $\num{7.321e+46}$ & $\num{-1.230e+15}$ & $\num{-2.850e+15}$\\
8 & $\num{9.649e+49}$ & $\num{9.649e+49}$ & $\num{-2.733e+15}$ & $\num{-3.771e+15}$\\
9 & $\num{9.794e+56}$ & $\num{9.794e+56}$ & $\num{3.113e+14}$ & $\num{-3.080e+15}$\\
10 & $\num{1.309e+61}$ & $\num{1.309e+61}$ & $\num{-4.653e+15}$ & $\num{-2.290e+15}$\\
11 & $\num{1.557e+64}$ & $\num{1.557e+64}$ & $\num{-3.221e+15}$ & $\num{-1.338e+15}$\\
12 & $\num{2.804e+68}$ & $\num{2.804e+68}$ & $\num{2.390e+16}$ & $\num{-4.244e+16}$\\
13 & $\num{3.928e+72}$ & $\num{3.928e+72}$ & $\num{1.223e+16}$ & $\num{-2.692e+16}$\\
14 & $\num{1.816e+78}$ & $\num{1.816e+78}$ & $\num{1.779e+16}$ & $\num{-4.409e+16}$\\
\end{tabular}
\end{document}
这就是 latex 代码。我的问题是,最右边的两列没有在符号上对齐\times
(因为有负数)。我怎样才能强制它沿着符号对齐\times
?
答案1
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{ c|
c|
c|
S[table-format =-1.3e+2]|
c}
& \multicolumn{2}{c}{Verbal} & \multicolumn{2}{c}{Math} \\
\hline
L & $\kappa\left(A^TA\right)$ & $2010$ & {$\kappa\left(A^TA\right)$ }& $2010$ \\
\hline
1 & $\num{1.000e+00}$ & $\num{1.000e+00}$ & 5.466e+02 & $\num{5.498e+02}$\\
2 & $\num{9.797e+11}$ & $\num{9.797e+11}$ & -1.874e+03 & $\num{-3.596e+02}$\\
3 & $\num{4.728e+22}$ & $\num{4.728e+22}$ & $\num{7.069e+04}$ & $\num{4.039e+05}$\\
4 & $\num{1.460e+27}$ & $\num{1.460e+27}$ & $\num{-2.279e+07}$ & $\num{-2.732e+08}$\\
5 & $\num{4.128e+32}$ & $\num{4.128e+32}$ & $\num{5.379e+10}$ & $\num{1.473e+10}$\\
6 & $\num{3.250e+40}$ & $\num{3.250e+40}$ & $\num{-1.329e+13}$ & $\num{2.339e+13}$\\
7 & $\num{7.321e+46}$ & $\num{7.321e+46}$ & $\num{-1.230e+15}$ & $\num{-2.850e+15}$\\
8 & $\num{9.649e+49}$ & $\num{9.649e+49}$ & $\num{-2.733e+15}$ & $\num{-3.771e+15}$\\
9 & $\num{9.794e+56}$ & $\num{9.794e+56}$ & $\num{3.113e+14}$ & $\num{-3.080e+15}$\\
10 & $\num{1.309e+61}$ & $\num{1.309e+61}$ & $\num{-4.653e+15}$ & $\num{-2.290e+15}$\\
11 & $\num{1.557e+64}$ & $\num{1.557e+64}$ & $\num{-3.221e+15}$ & $\num{-1.338e+15}$\\
12 & $\num{2.804e+68}$ & $\num{2.804e+68}$ & $\num{2.390e+16}$ & $\num{-4.244e+16}$\\
13 & $\num{3.928e+72}$ & $\num{3.928e+72}$ & $\num{1.223e+16}$ & $\num{-2.692e+16}$\\
14 & $\num{1.816e+78}$ & $\num{1.816e+78}$ & $\num{1.779e+16}$ & $\num{-4.409e+16}$\\
\end{tabular}
\end{document}
答案2
您可能喜欢以下解决方案:
编辑:
- 因为所有列都使用了
S
列类型,因此\num{...}
表体中的所有内容都被删除 - 删除所有垂直线
- 对于水平线,使用
booktabs
包中定义的规则 - 为了提高可读性,每隔一行后插入一个小的垂直空格
\addlinespace
\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{center}
\sisetup{print-zero-exponent}
\begin{tabular}{ S[table-format=2.0, print-zero-exponent=false]
*{2}{S[table-format =1.3e+2]}
*{2}{S[table-format =-1.3e+2]}
}
& \multicolumn{2}{c}{Verbal}
& \multicolumn{2}{c}{Math} \\
\cmidrule(r){2-3}\cmidrule(l){4-5}
L & {$(A^TA)$}& {2010} & {$\kappa(A^TA)$}
& {2010} \\
\midrule
1 & 1.000e+00 & 1.000e+00 & 5.466e+02 & 5.498e+02 \\
2 & 9.797e+11 & 9.797e+11 & -1.874e+03 & -3.596e+02 \\
\addlinespace
3 & 4.728e+22 & 4.728e+22 & 7.069e+04 & 4.039e+05 \\
4 & 1.460e+27 & 1.460e+27 & -2.279e+07 & -2.732e+08 \\
\addlinespace
5 & 4.128e+32 & 4.128e+32 & 5.379e+10 & 1.473e+10 \\
6 & 3.250e+40 & 3.250e+40 & -1.329e+13 & 2.339e+13 \\
\addlinespace
7 & 7.321e+46 & 7.321e+46 & -1.230e+15 & -2.850e+15 \\
8 & 9.649e+49 & 9.649e+49 & -2.733e+15 & -3.771e+15 \\
\addlinespace
9 & 9.794e+56 & 9.794e+56 & 3.113e+14 & -3.080e+15 \\
10 & 1.309e+61 & 1.309e+61 & -4.653e+15 & -2.290e+15 \\
\addlinespace
11 & 1.557e+64 & 1.557e+64 & -3.221e+15 & -1.338e+15 \\
12 & 2.804e+68 & 2.804e+68 & 2.390e+16 & -4.244e+16 \\
\addlinespace
13 & 3.928e+72 & 3.928e+72 & 1.223e+16 & -2.692e+16 \\
14 & 1.816e+78 & 1.816e+78 & 1.779e+16 & -4.409e+16 \\
\bottomrule
\end{tabular}
\end{center}
\end{document}
这使:
如您所见,数字与小数点完全对齐,并且所有数字在指数标记处都有相同的小数位数。
附录使用新颖的表格包 `tabularray`` 可以实现非常相似的结果。使用它会自动插入垂直间距:
\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs,
siunitx}
\ExplSyntaxOn
\NewChildSelector{eachtwo}
{
\int_step_inline:nnnn {2}{2}{\l_tblr_childs_total_tl}
{ \clist_put_right:Nn \l_tblr_childs_clist {##1} }
}
\ExplSyntaxOff
\begin{document}
\begin{center}
\sisetup{print-zero-exponent}
\begin{tblr}{colspec = { S[table-format=2.0, print-zero-exponent=false]
*{2}{S[table-format = 1.3e+2]}
*{2}{S[table-format =-1.3e+2]}
},
column{1}= {rightsep+=1.5em},
row{3-Z} = {rowsep=0pt},
row{2,3} = {abovesep+=2pt},
row{eachtwo} = {belowsep=1ex},
}
& \SetCell[c=2]{c} {{{Verbal}}}
& & \SetCell[c=2]{c} {{{Math}}}
& \\
\cmidrule[lr=-0.4]{2-3}\cmidrule[l=-0.4]{4-5}
L & \SetCell[c=1]{c} {{{$(A^TA)$}}}
& \SetCell[c=1]{c} {{{2010}}}
& \SetCell[c=1]{c} {{{$\kappa(A^TA)$}}}
& \SetCell[c=1]{c} {{{2010}}}
\\
\midrule
1 & 1.000e+00 & 1.000e+00 & 5.466e+02 & 5.498e+02 \\
2 & 9.797e+11 & 9.797e+11 & -1.874e+03 & -3.596e+02 \\
3 & 4.728e+22 & 4.728e+22 & 7.069e+04 & 4.039e+05 \\
4 & 1.460e+27 & 1.460e+27 & -2.279e+07 & -2.732e+08 \\
5 & 4.128e+32 & 4.128e+32 & 5.379e+10 & 1.473e+10 \\
6 & 3.250e+40 & 3.250e+40 & -1.329e+13 & 2.339e+13 \\
7 & 7.321e+46 & 7.321e+46 & -1.230e+15 & -2.850e+15 \\
8 & 9.649e+49 & 9.649e+49 & -2.733e+15 & -3.771e+15 \\
9 & 9.794e+56 & 9.794e+56 & 3.113e+14 & -3.080e+15 \\
10 & 1.309e+61 & 1.309e+61 & -4.653e+15 & -2.290e+15 \\
11 & 1.557e+64 & 1.557e+64 & -3.221e+15 & -1.338e+15 \\
12 & 2.804e+68 & 2.804e+68 & 2.390e+16 & -4.244e+16 \\
13 & 3.928e+72 & 3.928e+72 & 1.223e+16 & -2.692e+16 \\
14 & 1.816e+78 & 1.816e+78 & 1.779e+16 & -4.409e+16 \\
\bottomrule
\end{tblr}
\end{center}
\end{document}