[Tex/LaTex] Change section numbering for appendix

koma-scriptnumberingsectioningtable of contents

For my appendix I'm trying to change 3 things to my section numbering:

  1. Change to Alphabetical numbering
  2. Subsections of the appendix are not supposed to appear in the table of contents
  3. Numbering has to reset for my appendix, since I am using sections in my main part aswell

The result is supposed to look like this:

Appendix
A.1 Code 1
A.2 Code 2

For the table of contents its supposed to look like this:

5. Results ............. 50
Appendix ............... 51

I'm currently using the following code:

\documentclass[ DIV15,
liststotoc,
]{scrartcl}

\begin{document}

{
    \renewcommand{\thesection}{\thesection\Alph{section}}
    \renewcommand{\thesubsection}{\thesection.\Alph{subsection}}
}

\setcounter{section}{0}
\section*{Appendix}
\setcounter{section}{1}

\addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}
\subsection{Code 1}
\subsection{Code 2}
\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}

\end{document}

TexStudio compiles with no errors, but the page numbering for my appendix is still numeric. How can I change the numbering to alphabetical?
I've tried \def instead of \renewcommand but it did not help.

Thanks a lot in advance,
Phyrii

Best Answer

The line \renewcommand{\thesection}{\thesection\Alph{section}} creates a recursion loop. I think that you probably want

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

Secondly, since you are suppressing the section number in your MWE by using \section*, and given what you actually say, I think that you probably want:

\renewcommand{\thesubsection}{\Alph{section}.\arabic{subsection}}

Of course, you may actually have real sections in your document, in which case you should use

\renewcommand{\thesubsection}{\thesection.\arabic{subsection}}]

You could also potentially use \chapter here and \section instead of \subsection (or you could ignore these comments:)?

Finally, I am not sure what the intention of the two \addtocontents{toc}... commands is. If you comment out these two lines then a small variation of your MWE produces what I think you want:

enter image description here

Here is the full code:

\documentclass[ DIV15,
liststotoc,
]{scrartcl}

\begin{document}
\tableofcontents

\appendix
\renewcommand{\thesection}{\Alph{section}}
\renewcommand{\thesubsection}{\Alph{section}.\arabic{subsection}}

\section*{Appendix}

%\addtocontents{toc}{\protect\setcounter{tocdepth}{-1}}
\subsection{Code 1}
\subsection{Code 2}
%\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}

\end{document}
Related Question