Legenda da tabela não alinhada à esquerda no revtex

Legenda da tabela não alinhada à esquerda no revtex

Atualmente estou escrevendo um artigo APS e uso:

\documentclass[%
 reprint,
 amsmath,amssymb,
 aps,nofootinbib,
]{revtex4-1}
%
\usepackage{graphicx}
\usepackage{dcolumn}
\usepackage{bm}
\PassOptionsToPackage{linktocpage}{hyperref}
\usepackage[hyperindex,breaklinks]{hyperref}
\usepackage{tabularx}
\usepackage{enumitem}
\usepackage{slashed}
\usepackage{array}

As legendas das minhas figuras estão alinhadas à esquerda, como deveriam estar. As legendas da tabela, no entanto, serão centralizadas se eu usar o seguinte código:

{\renewcommand{\arraystretch}{1.2}
\begin{table*}[t]
  \centering
\begin{tabular*}{\textwidth}{l @{\extracolsep{\fill}} l l}
   \hline
   \hline
   \multicolumn{1}{c}{ \rule{0pt}{3ex} ...} & \multicolumn{1}{c}{...} & \multicolumn{1}{c}{...} \\
   \hline
... & ... & ... \\
    \hline
    \hline
    \end{tabular*}
    \caption{Centered caption.}\label{tab:1}
\end{table*}
}

Como posso alinhar as legendas da tabela à esquerda (e acima e não abaixo da tabela)?

Responder1

A revtex4-1classe document não oferece uma opção para desativar o comportamento indesejado, ou seja, as legendas curtas são sempre centralizadas. E como o captionpacote ainda não está adaptado, revtexé necessário corrigir o código responsável por você mesmo, por exemplo:

\long\def\@makecaption#1#2{%
  \par
  \vskip\abovecaptionskip
  \begingroup
   \small\rmfamily
   \sbox\@tempboxa{%
    \let\\\heading@cr
    \@make@capt@title{#1}{#2}%
   }%
   \@ifdim{\wd\@tempboxa >\hsize}{%
    \begingroup
     \samepage
     \flushing
     \let\footnote\@footnotemark@gobble
     \@make@capt@title{#1}{#2}\par
    \endgroup
   }{%
     \global \@minipagefalse
     \hb@xt@\hsize{\hfil\unhbox\@tempboxa\hfil}%
   }%
  \endgroup
  \vskip\belowcaptionskip
}%

pode ser corrigido para:

\long\def\@makecaption#1#2{%
  \par
  \vskip\abovecaptionskip
  \begingroup
   \small\rmfamily
    \begingroup
     \samepage
     \flushing
     \let\footnote\@footnotemark@gobble
     \@make@capt@title{#1}{#2}\par
    \endgroup
  \endgroup
  \vskip\belowcaptionskip
}

Como documento de exemplo completo:

\documentclass[%
 reprint,
 amsmath,amssymb,
 aps,nofootinbib,
]{revtex4-1}

\makeatletter
\renewcommand\@makecaption[2]{%
  \par
  \vskip\abovecaptionskip
  \begingroup
   \small\rmfamily
    \begingroup
     \samepage
     \flushing
     \let\footnote\@footnotemark@gobble
     \@make@capt@title{#1}{#2}\par
    \endgroup
  \endgroup
  \vskip\belowcaptionskip
}
\makeatother

\begin{document}

Some text...

\begin{table}
  Test
  \caption{Test}
\end{table}

Some text...

\end{document}

Uma solução mais elegante \patchcmdoferecida pelo etoolboxpacote [1]:

\documentclass[%
 reprint,
 amsmath,amssymb,
 aps,nofootinbib,
]{revtex4-1}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@makecaption}{\@ifdim{\wd\@tempboxa >\hsize}}{\@firstoftwo}{}{}
\makeatother

\begin{document}

Some text...

\begin{table}
  Test
  \caption{Test}
\end{table}

Some text...

\end{document}

Mas esteja ciente de que corrigir os internos de classes ou pacotes de documentos geralmente é uma má ideia, pois os internos estão sujeitos a alterações em versões futuras da classe ou pacote de documentos corrigidos.

[1] Veja também:Por favor, ensine o uso de patchcmd e xpatch

informação relacionada