我有以下代码。我的目标是使表格中的所有元素居中,并使表格适合页面。我搜索了类似的帖子,找到了几个,但它们的解决方案都不适合我。
\documentclass{IEEEtran}
\usepackage{cite}
\usepackage{amsmath}
\usepackage{amsthm}
\newtheorem{thm}{Theorem}
\newtheorem{lem}{Lemma}
\newtheorem{cor}{Corollary}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage{array}
\usepackage{siunitx}
\usepackage{booktabs}
\DeclareSymbolFont{matha}{OML}{txmi}{m}{it}% txfonts
\DeclareMathSymbol{\varv}{\mathord}{matha}{118}
\usepackage{caption}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{color}
\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother
\begin{table*}[htbp]
\centering
\caption{Caption}
\begin{tabular}{|c|p{6.21em}|p{4.055em}|c|p{5.63em}|p{4.13em}|c|p{5.79em}|p{4.13em}|c|}
\toprule
& \multicolumn{3}{c|}{d=0.0005} & \multicolumn{3}{c|}{d=0.001} & \multicolumn{3}{c|}{d=0.002} \\
\midrule
\multicolumn{1}{|p{6.29em}|}{SNR} & Estimated \newline{}Direction & \multicolumn{1}{c|}{Adjusted \newline{} Angular Distance} & \multicolumn{1}{p{5em}|}{Mean Adj.\newline{}Angular \newline{}Deviation} & Estimated \newline{}Direction & \multicolumn{1}{c|}{Adjusted Angular Distance} & \multicolumn{1}{p{4.79em}|}{Mean Adj.\newline{}Angular \newline{}Deviation} & Estimated \newline{}Direction & \multicolumn{1}{c|}{Adjusted \newline{}Angular Distance} & \multicolumn{1}{p{5.21em}|}{Mean Adj.\newline{}Angular\newline{}Deviation} \\
\midrule
30 & (48.6, 46.8)\newline{}(138.6, 45.0) & 3.83\newline{}3.6 & 3.715 & (48.6, 45)\newline{}(138.6, 45) & 3.6\newline{}3.6 & 3.6 & (48.6, 46.8)\newline{}(135, 43.2) & 3.83\newline{}1.27 & 2.55 \\
\midrule
20 & (48.5, 45)\newline{}(140.4, 46.8) & 3.5\newline{}5.53 & 4.515 & (48.6, 41.4)\newline{}(140.4, 48.6) & 4.45\newline{}5.92 & 5.185 & (48.6, 41.4)\newline{}(142.2, 46.8) & 4.45\newline{}7.30 & 5.875 \\
\midrule
10 & \textbf{(46.8, 46.8)\newline{}(142.2, 41.4)} & 2.22\newline{}7.58 & 4.9 & (46.8, 46.8)\newline{}(142.2, 43.2) & 2.22\newline{}7.30 & 4.76 & \textbf{(48.6, 48.6)\newline{}(140.4, 43.2)} & 4.45\newline{}5.53 & 4.99 \\
\bottomrule
\end{tabular}%
\label{tab:2nerve}%
\end{table*}%
感谢您的帮助!
答案1
下面的示例显示了两种不同的可能建议。
我使用了该siunitx
包来对齐数字与小数点分隔符。为了使表格变窄以适应文本宽度,我要么将列标题拆分为多行,要么引入缩写,这些缩写在表格下方描述。我还删除了所有垂直线,并包含一个水平线较少但有额外空白的变体。
\documentclass{IEEEtran}
\usepackage{array}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{makecell}
\usepackage{etoolbox}% <-- for bold fonts
\newcommand{\ubold}{\fontseries{b}\selectfont}% <-- for bold fonts
\robustify\ubold% <-- for bold fonts
\begin{document}
\begin{table*}[htbp]
\centering
\caption{Caption}
\begin{tabular}{c
*3{
r@{}
S[table-format=3.1]@{,~}
S[table-format=2.1]
@{}l
S[table-format=1.2]
S[table-format=1.3]
}
}
\toprule
& \multicolumn{6}{c}{d=0.0005} & \multicolumn{6}{c}{d=0.001} & \multicolumn{6}{c}{d=0.002} \\
\cmidrule(r){2-7} \cmidrule(lr){8-13} \cmidrule(l){14-19}
{SNR} & \multicolumn{4}{c}{\makecell[cc]{Estimated\\ Direction}} & {\makecell[cc]{Adjusted\\ Angular\\ Distance}} & {\makecell[cc]{Mean Adjusted\\ Angular\\ Distance}} & \multicolumn{4}{c}{\makecell[cc]{Estimated\\ Direction}} & {\makecell[cc]{Adjusted\\ Angular\\ Distance}} & {\makecell[cc]{Mean Adjusted\\ Angular\\ Distance}} & \multicolumn{4}{c}{\makecell[cc]{Estimated\\ Direction}} & {\makecell[cc]{Adjusted\\ Angular\\ Distance}} & {\makecell[cc]{Mean Adjusted\\ Angular\\ Distance}} \\
\midrule
30 & (&48.6 & 46.8&) & 3.83 & 3.715 & (&48.6& 45&) & 3.6& 3.6 & (&48.6& 46.8&) & 3.83 & 2.55 \\
& (&138.6& 45.0&) & 3.6 & 3.715 & (&138.6& 45&) & 3.6 & 3.6 & (&135& 43.2&) & 1.27 & 2.55 \\
\midrule
20 & (&48.5 & 45&) & 3.5 & 4.515 & (&48.6 & 41.4&) & 4.45 & 5.185 & (&48.6 & 41.4&) & 4.45 & 5.875 \\
& (&140.4 & 46.8&) & 5.53 & 4.515 & (&140.4 & 48.6&) & 5.92 & 5.185 & (&142.2 & 46.8&) & 7.30 & 5.875 \\
\midrule
10 & (&46.8 & 46.8&) & 2.22 & 4.9 & (&46.8 & 46.8&) & 2.22 & 4.76 & (&48.6 & 48.6&) & 4.45 & 4.99 \\
& (&142.2 & 41.4&) & 7.58 & 4.9 & (&142.2 & 43.2&) & 7.30 & 4.76 & (&140.4 & 43.2&) & 5.53 & 4.99 \\
\bottomrule
\end{tabular}%
\label{tab:2nerve}%
\end{table*}%
\begin{table*}[htbp]
\centering
\caption{Caption}
\begin{tabular}{c
*3{
r@{}
S[detect-weight,table-format=3.1]@{,~}
S[detect-weight,table-format=2.1]
@{}l
S[table-format=1.2]
S[table-format=1.3]
}
}
\toprule
& \multicolumn{6}{c}{d=0.0005} & \multicolumn{6}{c}{d=0.001} & \multicolumn{6}{c}{d=0.002} \\
\cmidrule(r){2-7} \cmidrule(lr){8-13} \cmidrule(l){14-19}
{SNR} & \multicolumn{4}{c}{ED} & {AAD} & {Mean AAD} & \multicolumn{4}{c}{ED} & {AAD} & {Mean AAD} &\multicolumn{4}{c}{ED} & {AAD} & {Mean AAD} \\
\midrule
30 & (&48.6 & 46.8&) & 3.83 & 3.715 & (&48.6& 45&) & 3.6& 3.6 & (&48.6& 46.8&) & 3.83 & 2.55 \\
& (&138.6& 45.0&) & 3.6 & 3.715 & (&138.6& 45&) & 3.6 & 3.6 & (&135& 43.2&) & 1.27 & 2.55 \\[3pt]
20 & (&48.5 & 45&) & 3.5 & 4.515 & (&48.6 & 41.4&) & 4.45 & 5.185 & (&48.6 & 41.4&) & 4.45 & 5.875 \\
& (&140.4 & 46.8&) & 5.53 & 4.515 & (&140.4 & 48.6&) & 5.92 & 5.185 & (&142.2 & 46.8&) & 7.30 & 5.875 \\[3pt]
10 & (& \ubold 46.8 &\ubold 46.8&) & 2.22 & 4.9 & (& \ubold 46.8 & \ubold 46.8&) & 2.22 & 4.76 & (& \ubold 48.6 & \ubold 48.6&) & 4.45 & 4.99 \\
& (& \ubold 142.2 & \ubold 41.4&) & 7.58 & 4.9 & (& \ubold 142.2 & \ubold 43.2&) & 7.30 & 4.76 & (& \ubold 140.4 & \ubold 43.2&) & 5.53 & 4.99 \\
\midrule
\multicolumn{19}{l}{ED = Estimated Direction,\quad AAD = Adjusted Angular Distance}\\
\bottomrule
\end{tabular}%
\label{tab:2nerve}%
\end{table*}%
\end{document}
根据列中的要求,以下是第二张表的摘录,其中没有所有“平均 AAD”列。代码包含注释(<------
)和与上述 MWE 相比的差异的简短描述。
\documentclass{IEEEtran}
\usepackage{array}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{etoolbox}% <-- for bold fonts
\newcommand{\ubold}{\fontseries{b}\selectfont}% <-- for bold fonts
\robustify\ubold% <-- for bold fonts
\begin{document}
\begin{table*}[htbp]
\centering
\caption{Caption}
\begin{tabular}{c
*3{
r@{}
S[detect-weight,table-format=3.1]@{,~}
S[detect-weight,table-format=2.1]
@{}l
S[table-format=1.2]
%%%S[table-format=1.3] % <---- Mean AAD columns
}
}
\toprule
& \multicolumn{5}{c}{d=0.0005} & \multicolumn{5}{c}{d=0.001} & \multicolumn{5}{c}{d=0.002} \\ %<------------ Changed from {6} to {5}
\cmidrule(r){2-6} \cmidrule(lr){7-11} \cmidrule(l){12-16} %<------- Changed from {2-7} to {2-6} ...
{SNR} & \multicolumn{4}{c}{ED} & {AAD} & \multicolumn{4}{c}{ED} & {AAD} &\multicolumn{4}{c}{ED} & {AAD} \\ %<------ Removed {Mean AAD}
\midrule
30 & (&48.6 & 46.8&) & 3.83 & (&48.6& 45&) & 3.6 & (&48.6& 46.8&) & 3.83 \\ % <---------- Removed corresponding values
& (&138.6& 45.0&) & 3.6 & (&138.6& 45&) & 3.6 & (&135& 43.2&) & 1.27 \\[3pt] % <---------- Removed corresponding values
\midrule
\multicolumn{16}{l}{ED = Estimated Direction,\quad AAD = Adjusted Angular Distance}\\ %<------------ Changed from {6} to {5}
\bottomrule
\end{tabular}%
\label{tab:2nerve}%
\end{table*}%
\end{document}