1

I am using document class elsarticle for drawing a table which should be both columns wide like this But my table is not going as wide, also how to shift table caption to left like shown in this figure. plz, guide. I am using the following code.

\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}

This is what I am getting.

2
  • That seems to be the correct width of your tabular, isn't it? You might want to place a \centering directly after \begin{table*} so that all its contents are centred, not just the caption.
    – Skillmon
    Sep 1, 2021 at 11:47
  • If you want a wider table you could use a package like tabularx and it's X type columns, but I don't think this is a particularly good idea here, tables with that much white space are just harder to read.
    – Skillmon
    Sep 1, 2021 at 12:02

1 Answer 1

2

I guess, you're interested in stretching the table from its natural width, that it currently has, to the entire linewidth. For this you could use tabular* in combination with \extracolsep{\fill}}. Since the table then contains a huge amount of wastes white space which does not really make the table more readable, I included an alternative layout that easily fits into one of the two document columns:

enter image description here

\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}
1
  • Thanks a lot, Just one question how can I shift the caption to the left as I mentioned in the question figure. regards Sep 1, 2021 at 18:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .