
Estou escrevendo uma tarefa e, de acordo com as instruções,
Os apêndices devem seguir o formato de nomenclatura “Apêndice S1”, Apêndice S2” e assim por diante.
Estou usando a elsarticle
classe. Até agora, eu tentei.
\appendix
\renewcommand{\thesection}{\Alph{section}}
Mas, por padrão, começa como A
. Existe alguma maneira de o formato de nomenclatura começar com S em vez de A?
Responder1
Os apêndices devem seguir o formato de nomenclatura “Apêndice S1”, Apêndice S2” e assim por diante.
A elsarticle
classe do documento contém as seguintes instruções bastante mal concebidas sobre as seções do apêndice e seu conteúdo:
\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}{}{}
}
Observe, em particular, a atrocidade \gdef\thesection{\appendixname~\@Alph\c@section}
, que torna impossível cruzar corretamente as seções do apêndice por meio de \autoref
e \cref
, que são duas macros de nível de usuário fornecidas pelos pacotes hyperref
e cleveref
, respectivamente.
Para obter a formatação desejada e restaurar os recursos normais de referência cruzada, sugiro que você execute as seguintes instruções após executar \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}
Responder2
eu concordo comAnálise de Micoque o código para \appendix
in elsarticle.cls
é terrível.
No entanto, não concordo com códigos complicados no meio do documento. Além disso, parecem necessárias algumas alterações à proposta do Mico, mas as suas ideias são, como sempre, muito boas.
\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}
Usar uma cópia da classe definida \@seccntformat
garante uniformidade na saída. Também alterei a forma como o índice é impresso para torná-lo semelhante ao elsarticle
do índice.
Não “abstraí” também a numeração do apêndice, mas o local onde ele está definido está claramente marcado.
Vantagem desta abordagem: se os editores não concordarem com o seu estilo, basta remover o código adicionado no preâmbulo. No entanto, se acontecer de você usar cleveref
, serão necessárias diversas alterações no documento.
Observe que isso cleveref
não é de forma alguma necessário para que o código funcione.
Responder3
\appendix
\setcounter{section}{18}%. is R, next will be S
\renewcommand{\thesection}{\Alph{section}}