我有下表:
\documentclass[12pt, a4paper]{article}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{tabularx}
\usepackage{array}
\usepackage{pdflscape}
\usepackage{longtable}
\usepackage{rotating}
\usepackage{afterpage}
\usepackage{textcomp}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning}
\usetikzlibrary{calc}
\usepackage{booktabs, siunitx}
\usepackage{dcolumn}
\NewExpandableDocumentCommand\mcc{O{1}m}
{\multicolumn{#1}{c}{#2}}
\begin{document}
\begin{table}[ht]
\centering
\scriptsize
\setlength\tabcolsep{0pt}
\caption{My caption}
\begin{tabular*}{\linewidth}{l @{\extracolsep{\fill}}*{5}{D{.}{.}{6}}}
\toprule
& \mcc[1]{1 (L)}
& \mcc[1]{2}
& \mcc[1]{3}
& \mcc[1]{4}
& \mcc[1]{5 (H)} \\
\midrule
\multicolumn{5}{l}{\textbf{This panel's title}}\\
\midrule
A (floats) $\beta$ &-0.49 &-0.17 &-0.01 & 0.16 & 0.47 \\
B (floats) &6.43 &6.91 &6.98 &6.92 &6.48 \\
C (integers) &136 &241 &342 &441 &536 \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}
该表包含双精度数和整数,并按 对齐浮点数.
。但是,我发现整数左对齐看起来有点奇怪。是否可以将它们右对齐?或者以某种方式对齐它,这样它看起来就不会像现在这么奇怪了。
答案1
使用该siunitx
包:
\documentclass[12pt, a4paper]{article}
\usepackage{array}
\usepackage{booktabs, siunitx}
\NewExpandableDocumentCommand\mcc{O{1}m}
{\multicolumn{#1}{c}{#2}}
\begin{document}
\begin{table}[ht]
\centering
%\scriptsize
\sisetup{table-format=-1.2,
table-text-alignment=right}
\setlength\tabcolsep{0pt}
\caption{My caption}
\begin{tabular*}{\linewidth}{l @{\extracolsep{\fill}}*{5}{S} }
\toprule
& \mcc{1 (L)} & \mcc{2} & \mcc{3} & \mcc{4} & \mcc{5 (H)} \\
\midrule
\multicolumn{5}{l}{\textbf{This panel's title}}\\
\midrule
A (floats) $\beta$
& -0.49 & -0.17 & -0.01 & 0.16 & 0.47 \\
B (floats) & 6.43 & 6.91 & 6.98 &6.92 & 6.48 \\
C (integers) & {136} & {241} & {342} & {44} & {536} \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}