4

I cannot make my table caption centered (it keeps staying on the left side) in a two-column manuscript. Here is the code I am using:

\documentclass[twocolumn]{autart}
\usepackage{graphicx} 
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage[justification=centering]{caption}

\begin{document}

\begin{table}
  \centering
  \caption{Nomenclature used in the model.} 
  \label{nomenclature}
  \vskip\baselineskip % Leave a vertical skip below the figure
  \begin{tabular}{|cc|} 
  \hline
          Col 1  &  Col 2          \\
          \hline
          1  &   4         \\
          2  &    5       \\
          3  &     6       \\
  \hline
  \end{tabular}
\end{table}
\end{document}

enter image description here

Can someone help me fix this?

7
  • 1
    Welcome to TeX.SE. Please tell us which document class you employ. Please also reveal whether the preamble of your document loads the caption package and, if so, the options employed with that package.
    – Mico
    Jan 2, 2022 at 10:16
  • @Mico thanks, I edited the code. I hope that's what you asked for.
    – Amin Shn
    Jan 2, 2022 at 10:20
  • I think normally the caption goes after the table? If you don't use it as the package specify it may not work properly
    – user202729
    Jan 2, 2022 at 10:21
  • @user202729 I tried changing caption's place but that didn't solve the problem.
    – Amin Shn
    Jan 2, 2022 at 10:25
  • 1
    @AminShn - The autart document class is not included automatically with TeXLive (one of the main TeX distributions). Is autart.cls available online somewhere?
    – Mico
    Jan 2, 2022 at 10:26

2 Answers 2

3

The following code is copied from the autart.cls file.

\long\def\@maketablecaption#1#2{\@tablecaptionsize
    \global \@minipagefalse
    \hbox to \hsize{\parbox[t]{\hsize}{#1 \\ #2}}}

This typesets the caption in a box over the complete horizontal space. Therefore \centering has no effect for your caption.

You could change the code of the autart.cls file, but I would not recommend doing this, since the current style is probably required.

If you insist doing this, you could add the following to your preamble.

\makeatletter
\long\def\@maketablecaption#1#2{\@tablecaptionsize
  \setbox\@tempboxa\hbox{#1. #2}
  \ifdim \wd\@tempboxa >\hsize              % IF longer than one line THEN
    \unhbox\@tempboxa\par                   %   set as justified paragraph
  \else                                     % ELSE
    \global \@minipagefalse
    \hbox to\hsize{\hfil\box\@tempboxa\hfil}%   center single line.
  \fi}
\makeatother

The code is copied from @makefigurecaption. The caption will be centered if it fits on one line, otherwise it will be a justified paragraph. See the examples I provided.

table output

2
  • 1
    You don't need to explicitly change the cls file. You can just enclose them within makeatletter...makeatother in the preamble and add the code here.
    – Imran
    Jan 2, 2022 at 11:32
  • 1
    @Imran thanks, I have updated to answer.
    – marv
    Jan 2, 2022 at 11:42
3

I think the "Automatica" journal wants the table caption to be like this (left-aligned rather than centered) and it doesn't look awful to me when there is some text around it. An example:

enter image description here

Yet if you want to center the caption, you can insert the \centering command in the 2nd mandatory argument of the parbox.

\documentclass[twocolumn]{autart}
\usepackage{graphicx} 
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage[justification=centering]{caption}

%--------------------------added---------------------------
\makeatletter
\long\def\@maketablecaption#1#2{\@tablecaptionsize
    \global \@minipagefalse
    \hbox to \hsize{\parbox[t]{\hsize}{\centering#1 \\ #2}}}
\makeatother
%-----------------------------------------------------------

\begin{document}
\begin{table}
    \centering
    \caption{Nomenclature used in the model.} 
    \label{nomenclature}
    \vskip\baselineskip % Leave a vertical skip below the figure
    \begin{tabular}{|cc|} 
        \hline
        Col 1  &  Col 2 \\
        \hline
        1  &   4        \\
        2  &    5       \\
        3  &     6      \\
        \hline
    \end{tabular}
\end{table}
\end{document}

enter image description here

You must log in to answer this question.

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