將附錄編號重新命名為 S1 和 S2,而不是 A 和 B

將附錄編號重新命名為 S1 和 S2,而不是 A 和 B

我正在寫作業,按照說明,

附錄必須遵循「附錄 S1」、「附錄 S2」等命名格式。

我正在使用該類別elsarticle。到目前為止,我已經嘗試過了。

\appendix
\renewcommand{\thesection}{\Alph{section}}

但是,它預設以A.有什麼辦法可以讓命名格式從S開始而不是從A開始嗎?

答案1

附錄必須遵循「附錄 S1」、「附錄 S2」等命名格式。

文件elsarticle類別包含以下有關附錄部分及其內容的相當不周密的說明:

\def\appendixname{Appendix }
\renewcommand\appendix{\par
  \setcounter{section}{0}%
  \setcounter{subsection}{0}%
  \setcounter{equation}{0}
  \gdef\thefigure{\@Alph\c@section.\arabic{figure}}%
  \gdef\thetable{\@Alph\c@section.\arabic{table}}%
  \gdef\thesection{\appendixname~\@Alph\c@section}%
  \@addtoreset{equation}{section}%
  \gdef\theequation{\@Alph\c@section.\arabic{equation}}%
  \addtocontents{toc}{\string\let\string\numberline\string\tmptocnumberline}{}{}
}

請特別注意 atrocity ,它使得無法通過和\gdef\thesection{\appendixname~\@Alph\c@section}正確交叉引用附錄部分,這兩個巨集分別是由和包提供的兩個用戶級巨集。\autoref\crefhyperrefcleveref

為了實現您想要的格式並恢復正常的交叉引用功能,我建議您在執行後執行以下指令\appendix

\makeatletter
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
   {\csname the#1\endcsname\space}%    default
   {\csname #1@cntformat\endcsname}}%  enable individual control
\newcommand\section@cntformat{\appendixname\thesection.\space} % section-level
\makeatother
\renewcommand{\thesection}{S\arabic{section}}
\counterwithin{equation}{section}
\counterwithin{figure}{section}
\counterwithin{table}{section}

在此輸入影像描述

\documentclass{elsarticle}
\usepackage{cleveref} % for '\cref' command
\begin{document}

\section{Introduction}

\noindent
Cross-references to \cref{app:hello,app:world,eq:pyth,fig:here,tab:there}. 


\appendix

\makeatletter
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
   {\csname the#1\endcsname\space}%    default
   {\csname #1@cntformat\endcsname}}%  enable individual control
\newcommand\section@cntformat{\appendixname\thesection.\space} % section-level
\makeatother
\renewcommand{\thesection}{S\arabic{section}}
\counterwithin{equation}{section}
\counterwithin{figure}{section}
\counterwithin{table}{section}

\section{Hello} \label{app:hello}
\begin{equation}\label{eq:pyth} a^2+b^2=c^2 \end{equation}
\begin{figure}[h] \caption{A figure caption}\label{fig:here} \end{figure}

\section{World} \label{app:world}
\begin{table}[h] \caption{A table caption}\label{tab:there} \end{table}

\end{document}

答案2

我同意米科的分析\appendixin的程式碼elsarticle.cls很糟糕。

但是,我不同意文檔中間有複雜的程式碼。另外,對 Mico 的提案進行一些修改似乎是必要的,但他的想法一如既往地非常好。

\documentclass{elsarticle}
\usepackage{cleveref} % for '\cref' command

\makeatletter
\newif\if@els@appendix
\renewcommand\appendix{\par
  \global\@els@appendixtrue
  \setcounter{section}{0}%
  \setcounter{subsection}{0}%
  \setcounter{equation}{0}%
  \counterwithin{figure}{section}%
  \counterwithin{table}{section}%
  \counterwithin{equation}{section}%
  \gdef\thesection{S\arabic{section}}% <--- HERE THE NUMBERING FORMAT
  \addtocontents{toc}{\string\let\string\numberline\string\tmptocnumberline}{}{}
}
\NewCommandCopy{\els@seccntformat}{\@seccntformat}
\renewcommand{\@seccntformat}[1]{%
  \ifcsname format@#1\endcsname
    \csname format@#1\endcsname
  \else
    \els@seccntformat{#1}%
  \fi
}
\newcommand{\format@section}{%
  \if@els@appendix \appendixname\fi\els@seccntformat{section}%
}
\def\tmptocnumberline#1{%
   \settowidth\appnamewidth{\appendixname S00}%
   \hb@xt@\appnamewidth{\appendixname #1\hfill}%
}
\makeatother

\begin{document}

\tableofcontents

\section{Introduction}

Cross-references to \cref{app:hello,app:world,eq:pyth,fig:here,tab:there}. 

\appendix

\section{Hello} \label{app:hello}
\begin{equation}\label{eq:pyth} a^2+b^2=c^2 \end{equation}
\begin{figure}[htp] \caption{A figure caption}\label{fig:here} \end{figure}

\section{World} \label{app:world}
\begin{table}[htp] \caption{A table caption}\label{tab:there} \end{table}

\end{document}

使用定義的類別的副本\@seccntformat可確保輸出的一致性。我還更改了目錄的列印方式,使其與elsarticle的類似。

我也沒有「抽象」附錄的編號,但定義它的地方已經清楚地標記了。

這種方法的優點:如果文案編輯不同意您的風格,您只需刪除序言中新增的程式碼即可。但是,如果您碰巧使用cleveref,則需要對文件進行一些更改。

請注意,這cleveref絕不是程式碼運行所必需的。

在此輸入影像描述

答案3

\appendix
\setcounter{section}{18}%. is R, next will be S
\renewcommand{\thesection}{\Alph{section}}

相關內容