表格標題未在 revtex 中左對齊

表格標題未在 revtex 中左對齊

我目前正在寫一篇 APS 文章並使用:

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

我的圖形標題是左對齊的,正如它們應該的那樣。但是,如果我使用以下程式碼,表格標題將會居中:

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

如何使表格標題左對齊(並且在表格上方而不是下方)?

答案1

文件revtex4-1類別不提供關閉不需要的行為的選項,即短標題始終居中。由於該caption套件尚未適應revtex,因此需要自行修補負責的程式碼,例如:

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

可以修補為:

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

作為完整的範例文件:

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

使用包 [1]\patchcmd提供的更優雅的解決方案:etoolbox

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

但請注意,修補文件類別或套件的內部結構通常是一個壞主意,因為內部結構可能會在修補的文檔類別或套件的未來版本中發生變化。

[1] 另見:請指導patchcmd和xpatch的使用

相關內容