语言, Latex专题

在Latex附录文件中的图片和公式序号前面加个'S'字母

如果需要在Latex附录文件中的图片和公式序号前面都加个'S'字母,可增加语句:

\renewcommand{\thefigure}{S\arabic{figure}}  
\renewcommand{\theequation}{S\arabic{equation}} 

以下是测试例子【为了能在网页上显示,这里需要手动将\ref_1和\ref_2改为\ref后再编译运行】:

\documentclass{article}
\usepackage{graphicx}

% 加上以下语句,S字母可任意修改
\renewcommand{\thefigure}{S\arabic{figure}}  
\renewcommand{\theequation}{S\arabic{equation}} 

\begin{document}

Here are Eq. (\ref_1{eq:mass_energy_equivalence}) and Fig. \ref_2{fig:a}.

\begin{equation}
    E=mc^2 \label{eq:mass_energy_equivalence}
\end{equation}

\begin{figure}[htbp]
    % \includegraphics*[width=0.5\textwidth]{a.eps}
    \caption{This is a caption. Image is not shown.}
    \label{fig:a}
\end{figure}

\end{document}

运行结果:

1,086 次浏览

【说明:本站主要是个人的一些笔记和代码分享,内容可能会不定期修改。为了使全网显示的始终是最新版本,这里的文章未经同意请勿转载。引用请注明出处:https://www.guanjihuan.com

4 thoughts on “在Latex附录文件中的图片和公式序号前面加个'S'字母”

  1. 博主,你好,我想问一下怎样在 revtex 4-2 的编译环境下在参考文献的序号前加 “S” ?

    1. 如果是常规环境,可以使用:

      \makeatletter
      \renewcommand{\@biblabel}[1]{[S#1]} % 序号格式为 [S1], [S2]...
      \renewcommand{\@cite}[1]{[S#1]} % 更改引用格式为 [S1], [S2], ...
      \makeatother

      但在 revtex 4-2 的环境下,上面的方法好像是不起作用的。

      如果是使用 bibtem,可以用这个方法:

      \documentclass[aps,prl,twocolumn,superscriptaddress]{revtex4-2}
      \usepackage{ctex}
      \begin{document}
      这是一个引用~\cite{example}。
      \begin{thebibliography}{9}
      \bibitem[S1]{example} 作者,文章标题,期刊名,年份。
      \end{thebibliography}
      \end{document}

      我目前还不知道在 bib 中怎么实现,有可能需要复制修改 revtex 4-2 的 .bst 文件来解决。

    1. 可以使用:

      \makeatletter
      \renewcommand{\@biblabel}[1]{[S#1]} % 序号格式为 [S1], [S2]...
      \renewcommand{\@cite}[1]{[S#1]} % 更改引用格式为 [S1], [S2], ...
      \makeatother

      或者

      \documentclass{article}
      \usepackage{ctex}
      \begin{document}
      这是一个引用~\cite{example}。
      \begin{thebibliography}{9}
      \bibitem[S1]{example} 作者,文章标题,期刊名,年份。
      \end{thebibliography}
      \end{document}

      如果是 bib 形式会比较复杂,可能需要修改 .bst 文件,具体实现方法可以问 AI。

      另外,下面这个例子不一定起作用,先记录在这里:

      \documentclass{article}
      \usepackage{ctex}
      \usepackage{etoolbox}
      % 在每个 \bibitem 标签前自动添加 "S"
      \makeatletter
      \patchcmd{\@biblabel}{\thebibliography}{S\@arabic}
      \makeatother
      \begin{document}
      这是一个引用~\cite{example}。
      \begin{thebibliography}{9}
      \bibitem{example} 作者,文章标题,期刊名,年份。
      \end{thebibliography}
      \end{document}

发表评论

您的邮箱地址不会被公开。 必填项已用 * 标注

Captcha Code