
私は課題を書いていますが、指示に従って、
付録は、「付録 S1」、「付録 S2」などの命名形式に従う必要があります。
私はそのelsarticle
クラスを使用しています。これまで試してきました。
\appendix
\renewcommand{\thesection}{\Alph{section}}
しかし、デフォルトでは で始まりますA
。命名形式を A ではなく S で始める方法はありますか?
答え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
によって提供される 2 つのユーザー レベル マクロです。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
ひどいです。
しかし、ドキュメントの途中にある複雑なコードには同意できません。また、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}}