我正在使用文档类 elsarticle 来绘制一个表格,该表格应该像 但是我的表格不够宽,如何将表格标题向左移动,如图所示。请指导。我正在使用以下代码。
\documentclass[final, 5p, times, twocolumn]{elsarticle}
%\documentclass[times]{elsarticle}
\journal{Nuclear Physics B}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{fullpage}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{hyperref}
\begin{document}
\begin{table*}[h]
\caption{Confusion Matrix for EmoDB Datset}
\begin{tabular}{l c c c c c cc}
\hline
&angry&boredom&disgust&fear&happy&sadness&neutral\\
\hline
angry&\textbf{0.96}&0.00&0.00&0.01&0.03&0.00&0.00\\
boredom&0.00&\textbf{0.92}&0.00&0.01&0.00&0.02&0.05\\
disgust&0.00&0.00&\textbf{100}&0.00&0.00&0.00&0.00\\
fear&0.00&0.00&0.00&\textbf{0.93}&0.02&0.00&0.05\\
happy&0.08&0.00&0.00&0.00&\textbf{0.90}&0.00&0.02\\
sadness&0.00&0.00&0.00&0.00&0.00&\textbf{100}&0.00\\
neutral&0.00&0.06&0.00&0.00&0.00&0.03&\textbf{0.91}\\
\hline
\end{tabular}
\end{table*}
\end{document}
答案1
我猜,你有兴趣将表格从其当前的自然宽度拉伸到整个线宽。为此,你可以tabular*
结合使用\extracolsep{\fill}}
。由于表格包含大量浪费的空白,这实际上并没有使表格更具可读性,因此我提供了一种可轻松放入两个文档列之一的替代布局:
\documentclass[final, 5p, times, twocolumn]{elsarticle}
%\documentclass[times]{elsarticle}
\journal{Nuclear Physics B}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{fullpage}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{rotating, makecell}
\usepackage{lipsum} % for dummy text using the \lipsum command, do not use in real document.
\usepackage{hyperref}
\begin{document}
\begin{table*}[h]
\caption{Confusion Matrix for EmoDB Datset}
\begin{tabular*}{\linewidth}{l @{\extracolsep{\fill}}c c c c c cc}
\toprule
&angry&boredom&disgust&fear&happy&sadness&neutral\\
\midrule
angry&\textbf{0.96}&0.00&0.00&0.01&0.03&0.00&0.00\\
boredom&0.00&\textbf{0.92}&0.00&0.01&0.00&0.02&0.05\\
disgust&0.00&0.00&\textbf{100}&0.00&0.00&0.00&0.00\\
fear&0.00&0.00&0.00&\textbf{0.93}&0.02&0.00&0.05\\
happy&0.08&0.00&0.00&0.00&\textbf{0.90}&0.00&0.02\\
sadness&0.00&0.00&0.00&0.00&0.00&\textbf{100}&0.00\\
neutral&0.00&0.06&0.00&0.00&0.00&0.03&\textbf{0.91}\\
\bottomrule
\end{tabular*}
\end{table*}
\begin{table}
\renewcommand{\theadfont}{\normalsize}
\settowidth\rotheadsize{\theadfont boredom}
\setlength{\tabcolsep}{0pt}
\caption{Confusion Matrix for EmoDB Datset}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}l c c c c c cc@{}}
\toprule
&\rothead{angry} &\rothead{boredom} & \rothead{disgust} & \rothead{fear} & \rothead{happy} & \rothead{sadness} & \rothead{neutral}\\
\midrule
angry & \textbf{0.96}&0.00&0.00&0.01&0.03&0.00&0.00\\
boredom & 0.00&\textbf{0.92}&0.00&0.01&0.00&0.02&0.05\\
disgust & 0.00&0.00&\textbf{100}&0.00&0.00&0.00&0.00\\
fear & 0.00&0.00&0.00&\textbf{0.93}&0.02&0.00&0.05\\
happy & 0.08&0.00&0.00&0.00&\textbf{0.90}&0.00&0.02\\
sadness & 0.00&0.00&0.00&0.00&0.00&\textbf{100}&0.00\\
neutral & 0.00&0.06&0.00&0.00&0.00&0.03&\textbf{0.91}\\
\bottomrule
\end{tabular*}
\end{table}
\lipsum
\lipsum
\end{document}