
Я пишу задание, и согласно инструкции,
Приложения должны иметь следующий формат наименования: «Приложение 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}{}{}
}
Обратите внимание, в частности, на чудовищность \gdef\thesection{\appendixname~\@Alph\c@section}
, из-за которой невозможно правильно ссылаться на разделы приложений с помощью \autoref
и \cref
, которые представляют собой два макроса пользовательского уровня, предоставляемые пакетами hyperref
и cleveref
соответственно.
Чтобы добиться желаемого форматирования и восстановить нормальные возможности перекрестных ссылок, я предлагаю вам выполнить следующие инструкции после выполнения \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
Я согласен сАнализ Микочто код для \appendix
in elsarticle.cls
ужасен.
Однако я не согласен со сложным кодом в середине документа. Также некоторые изменения в предложении Мико кажутся необходимыми, но его идеи, как обычно, очень хороши.
\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
's.
Я не «абстрагировал» также нумерацию приложения, но место, где она определена, четко обозначено.
Преимущество этого подхода: если редакторы не согласны с вашим стилем, вы просто удаляете добавленный код в преамбуле. Однако, если вы используете cleveref
, потребуется внести несколько изменений в документ.
Обратите внимание, что cleveref
это вовсе не обязательно для работы кода.
решение3
\appendix
\setcounter{section}{18}%. is R, next will be S
\renewcommand{\thesection}{\Alph{section}}