付録番号をAとBからS1とS2に変更

付録番号をAとBからS1とS2に変更

私は課題を書いていますが、指示に従って、

付録は、「付録 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 つのユーザー レベル マクロです。hyperrefcleveref

希望する書式設定を実現し、通常の相互参照機能を復元するには、 を実行した後に次の手順を実行することをお勧めします\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}}

関連情報