3

I am writing an assignment, and as per the instructions,

Appendices must follow the naming format “Appendix S1,” Appendix S2,” and so on.

I am using the elsarticle class. So far, I have tried.

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

But, it by default starts as A. Is there any way the naming format can start from S instead of A?

2
  • Your title agrees with the instructions, but disagrees with your last paragraph.
    – Teepeemm
    Feb 2 at 15:57
  • While it's ok to upvote answers that you find useful immediately, site instructions strongly suggest waiting for at least a few hours, and ideally a day or more, before "accepting" any particular answer. That way, you don't inadvertently discourage other readers from posting additional, and potentially even better, answers.
    – Mico
    Feb 2 at 16:10

3 Answers 3

6

Appendices must follow the naming format “Appendix S1,” Appendix S2,” and so on.

The elsarticle document class contains the following, rather ill-conceived instructions regarding appendix sections and their contents:

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

Notice, in particular, the atrocity \gdef\thesection{\appendixname~\@Alph\c@section}, which makes is impossible to cross-reference appendix sections properly via \autoref and \cref, which are two user-level macros provided by the hyperref and cleveref packages, respectively.

To achieve your desired formatting and to restore normal cross-referencing capabilities, I suggest you run the following instructions after executing \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}

enter image description here

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

I concur with Mico's analysis that the code for \appendix in elsarticle.cls is dreadful.

However, I don't agree with complicated code in the middle of the document. Also, some changes to Mico's proposal seem necessary, but his ideas are, as usual, very good.

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

Using a copy of the class defined \@seccntformat ensures uniformity in the output. I also change how the table of contents is printed so as to make it similar to elsarticle’s.

I didn't “abstract” also the numbering of the appendix, but the place where it's defined is clearly marked.

Advantage of this approach: if the copy editors don't agree with your style, you just remove the added code in the preamble. However, if you happen to use cleveref, several changes in the document would be needed.

Note that cleveref is by no means necessary for the code to work.

enter image description here

2
\appendix
\setcounter{section}{18}%. is R, next will be S
\renewcommand{\thesection}{\Alph{section}}
1
  • 3
    This doesn't quite work: The first appendix section will be labeled S, the second appendix section will be labeled T, and so on. According to the OP's write-up, though, the appendix sections are supposed to be numbered S1, S2, etc.
    – Mico
    Feb 2 at 15:11

You must log in to answer this question.

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