2

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

  • Have you tried putting the \appendix command before the start of the appendix? If not then can you please expand your code snippets into a compliable minimal working example. In particular, it would help to know what document class you are using. – Andrew Jul 20 '18 at 9:09
  • Okay the \appendix made a lot of my code obsolete. Doing everything of the above, it's not showing the page number in the table of contents, though. Any ideas? I also added my documentclass, sorry for that. – Phyrii Jul 20 '18 at 11:10
1

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 also want:

\renewcommand{\thesubsection}{A.\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, but if you take them you 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}{A.\arabic{subsection}}

\section*{Appendix}

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

\end{document}
0

With a KOMA-Script class I would use:

\addsec{Appendix}%
\refstepcounter{section}%
\addtocontents{toc}{\protect\value{tocdepth}=\parttocdepth}%

Example:

\documentclass[
  DIV=15,% <- syntax changed!
  listof=totoc,% <- syntax changed!
]{scrartcl}

\usepackage{xpatch}
\xapptocmd{\appendix}{%
  \addsec{Appendix}%
  \refstepcounter{section}%
  \addtocontents{toc}{\protect\value{tocdepth}=\parttocdepth}%
}{}{}

\usepackage{blindtext}% only for dummy text

\begin{document}
\tableofcontents

\Blinddocument

\appendix
\subsection{Code 1}
\subsection{Code 2}

\end{document}

Result:

enter image description here

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.