为什么表格标题左侧有一个额外的海军空间?
另外,我希望对角线能够正确拟合,有任何帮助吗?
\documentclass[a4paper,12pt]{article}
\usepackage{pict2e}
\usepackage[svgnames, table, x11names]{ xcolor}%
\usepackage{caption, tabularx, booktabs, hhline}
\usepackage{diagbox, eqparbox, hhline}
\setlength{\arrayrulewidth}{0.5mm}
\setlength{\tabcolsep}{20pt}
\renewcommand{\arraystretch}{1.5}
\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}
\begin{document}
\rowcolors{2}{PowderBlue!50}{PowderBlue!25}
\begin{table}[H]
\centering
\caption{Decreasing percentage in amplitude}
\medskip
\label{tab:amplitude decreasing percentage}
\begin{tabular}[H]{>{\hspace{-1\tabcolsep}} *{6} {>{$}c<{$}}<{\hspace{-1\tabcolsep}}}
\rowcolor{Navy!80} \toprule
\textbf{\diagbox[height=8ex, width=4.5cm]{\raisebox{0.1\height}{\enspace\color{white}variables}}{ \raisebox{-1.5\height}{\, \color{white}$\Phi$}}}
& \color{white} 0.1\% &\color{white} 0.5\% &\color{white} 1\% & \color{white}1.5\% & \color{white}2\% \\ \midrule
x & 3.34 & 16.19 & 31.11 & 44.65 & 56.77 \\
y & 3.23 & 15.73 & 30.38 & 43.79 & 55.91 \\
\dot{x} & 3.36 & 16.2 & 31.09 & 44.61 & 56.80 \\
\dot{y} & 3.23 & 15.73 & 30.38 & 43.77 & 55.91 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
错误在于您的>{\hspace{-1\tabcolsep}}
。我借此机会使用siunitx
将数字对齐到小数点并简化代码:
\documentclass[a4paper,12pt]{article}
\usepackage{pict2e}
\usepackage{amsmath}
\usepackage[svgnames, table, x11names]{ xcolor}%
\usepackage{caption, tabularx, booktabs, hhline}
\usepackage{diagbox, eqparbox, hhline}
\setlength{\arrayrulewidth}{0.5mm}
\setlength{\tabcolsep}{20pt}
\renewcommand{\arraystretch}{1.5}
\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}
\usepackage{siunitx}
\sisetup{table-number-alignment=center}
\begin{document}
\rowcolors{2}{PowderBlue!50}{PowderBlue!25}
\begin{table}
\centering
\caption{Decreasing percentage in amplitude}
\medskip
\label{tab:amplitude decreasing percentage}%>{\hspace{-1\tabcolsep}}, height=8ex,
\begin{tabular}{>{$}c<{$}S[table-format=1.2]*{4} {S[table-format=2.2]}}
\rowcolor{Navy!60}%
\toprule
\textbf{\diagbox[width=4cm, linecolor=PowderBlue!50,linewidth=1.2pt]{\raisebox{0ex}{\color{white}variables}}{ \raisebox{-1.5\height}{\, \color{white}$\boldsymbol\Phi$}}}
& {\color{white}\bfseries 0.1\,\%} &{\color{white}\bfseries 0.5\,\%} &{\color{white}\bfseries 1\,\%} & {\color{white}\bfseries1.5\,\%} & {\color{white}\bfseries 2\,\%} \\ \midrule
x & 3.34 & 16.19 & 31.11 & 44.65 & 56.77 \\
y & 3.23 & 15.73 & 30.38 & 43.79 & 55.91 \\
\dot{x} & 3.36 & 16.2 & 31.09 & 44.61 & 56.80 \\
\dot{y} & 3.23 & 15.73 & 30.38 & 43.77 & 55.91 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
环境{NiceTabular}
有nicematrix
自己的命令\diagbox
来削减细胞。
\documentclass[a4paper,12pt]{article}
\usepackage{geometry}
\usepackage[svgnames]{xcolor}
\usepackage{nicematrix}
\usepackage{caption,booktabs}
\usepackage{siunitx}
\sisetup{table-number-alignment=center}
\begin{document}
\begin{table}
\caption{Decreasing percentage in amplitude}
\label{tab:amplitude decreasing percentage}
\centering
\renewcommand{\arraystretch}{1.5}
\setlength{\tabcolsep}{15pt}
\begin{NiceTabular}{w{c}{15mm}S[table-format=1.2]*{4}{S[table-format=2.2]}}
\CodeBefore
\rowcolors{2}{PowderBlue!50}{PowderBlue!25}
\rowcolor{Navy!60}{1}
\Body
\toprule
\diagbox{\color{white}variables}{\color{white}\strut$\boldsymbol\Phi$}
\RowStyle{\color{white}\bfseries}
& {0.1\,\%} & {0.5\,\%} & {1\,\%} & {1.5\,\%} & {2\,\%} \\
\midrule
$x$ & 3.34 & 16.19 & 31.11 & 44.65 & 56.77 \\
$y$ & 3.23 & 15.73 & 30.38 & 43.79 & 55.91 \\
$\dot{x}$ & 3.36 & 16.2 & 31.09 & 44.61 & 56.80 \\
$\dot{y}$ & 3.23 & 15.73 & 30.38 & 43.77 & 55.91 \\
\bottomrule
\end{NiceTabular}
\end{table}
\end{document}
但是,规则是用\diagbox
规则的当前颜色绘制的(可以使用 设置\arrayrulecolor
)。如果您想要白色规则,则必须使用 TikZ 和由 创建的 PGF/TikZ 节点在第一条规则上绘制第二条规则nicematrix
。
\documentclass[a4paper,12pt]{article}
\usepackage{geometry}
\usepackage[svgnames]{xcolor}
\usepackage{nicematrix,tikz}
\usepackage{caption,booktabs}
\usepackage{siunitx}
\sisetup{table-number-alignment=center}
\begin{document}
\begin{table}
\caption{Decreasing percentage in amplitude}
\label{tab:amplitude decreasing percentage}
\centering
\renewcommand{\arraystretch}{1.5}
\setlength{\tabcolsep}{15pt}
\begin{NiceTabular}{w{c}{15mm}S[table-format=1.2]*{4}{S[table-format=2.2]}}
\CodeBefore
\rowcolors{2}{PowderBlue!50}{PowderBlue!25}
\rowcolor{Navy!60}{1}
\Body
\toprule
\diagbox{\color{white}variables}{\color{white}\strut$\boldsymbol\Phi$}
\RowStyle{\color{white}\bfseries}
& {0.1\,\%} & {0.5\,\%} & {1\,\%} & {1.5\,\%} & {2\,\%} \\
\midrule
$x$ & 3.34 & 16.19 & 31.11 & 44.65 & 56.77 \\
$y$ & 3.23 & 15.73 & 30.38 & 43.79 & 55.91 \\
$\dot{x}$ & 3.36 & 16.2 & 31.09 & 44.61 & 56.80 \\
$\dot{y}$ & 3.23 & 15.73 & 30.38 & 43.77 & 55.91 \\
\bottomrule
\CodeAfter \tikz \draw [white,thick] (1-|1) -- (2-|2) ;
\end{NiceTabular}
\end{table}
\end{document}