2

I've tried different settings from other examples on this topics to get the appendix that I want for 2 days to no avail, I hope someone can help me out of my misery.

I would like to have an appendix that looks like the result from my code (no number before "Appendix", appendices appearing as A.1, A.2,...) but it shows up in the list of contents in a weird way under the last real chapter of the document. What I want is on the last picture below, just the name Appendix in the TOC without subentries. I added a list of figures because some examples I tried made every figure appear in the TOC, which it shouldn't.

\documentclass[listof=totoc,oneside]{scrreprt}  
\usepackage[toc,nonumberlist]{glossaries}
\makeglossaries

\begin{document}
\tableofcontents
\listoffigures
\chapter{Chapter One}
\section{Section One}
\chapter{Chapter Two}
\section{Section One}
\begin{figure}[h]
\caption{A Caption}
\end{figure}

\appendix
\chapter*{Appendix}
\renewcommand*{\thesection}{A.\arabic{section}}
\section{test 1}
Text
\section{test 2}

\end{document}

Makes: now http://i66.tinypic.com/nlrbcl.jpg

How it should appear in the list of contents:

want http://i66.tinypic.com/oargxj.jpg

  • (Edit: Ok, I got rid of my previous error message.) There is one other problem, the Appendix is fixed but now the list of figures doesn't work anymore, there are no entries in the glossary :/ – Nicole W. Mar 2 '17 at 17:25
2

Here is another suggestion:

\documentclass[listof=totoc,oneside]{scrreprt}
\usepackage[toc,nonumberlist]{glossaries}
\makeglossaries

\newcommand\savedtocdepth{}
\BeforeStartingTOC[toc]{%
  \edef\savedtocdepth{\the\value{tocdepth}}%
}
\AfterStartingTOC[toc]{%
  \setcounter{tocdepth}{\savedtocdepth}%
}
\usepackage{xpatch}
\xapptocmd\appendix
  {%
    \addchap{Appendix}%
    \addtocontents{toc}{\setcounter{tocdepth}{0}}%
    \renewcommand*{\thesection}{A.\arabic{section}}%
  }
  {}{\PatchFailed}


\begin{document}
\tableofcontents
\listoffigures
\chapter{Chapter One}
\section{Section One}
\chapter{Chapter Two}
\section{Section One}
\begin{figure}[h]
\caption{A Caption}
\end{figure}

\appendix
\section{test 1}
Text
\section{test 2}

\end{document}
2

One more suggestion similar to @esdd's:

\documentclass[listof=totoc]{scrreprt}% oneside is default
\usepackage[toc,nonumberlist]{glossaries}
\makeglossaries

\usepackage{xpatch}
\xapptocmd{\appendix}{%
  \addchap{Appendix}%
  \refstepcounter{chapter}%
  \addtocontents{toc}{\protect\value{tocdepth}=\chaptertocdepth}%
}{}{}

\begin{document}
\tableofcontents
\listoffigures
\chapter{Chapter One}
\section{Section One}
\chapter{Chapter Two}
\section{Section One}
\begin{figure}[h]
\caption{A Caption}
\end{figure}

\appendix
\section{test 1}
Text
\section{test 2}

\end{document}

The first difference is, that it uses \chaptertocdepth instead of an absolute number and changes \value{tocdepth} instead of using \setcounter{tocdepth}, because \setcounter is global and changing \value {tocdepth} is local. So it does not need to store and restore the original value.

The second is, that it does not redefine \thesection but simply increases counter chapter in \appendix. You could also use \setcounter{chapter}{1} instead of \refstepcounter{chapter}, if you do not need a label to the appendix.

A third recommended difference for KOMA-Script from version 3.23 would be to use \ext@toc instead of toc to write into the auxiliary file for the ToC:

\usepackage{xpatch}
\xapptocmd{\appendix}{%
  \addchap{Appendix}%
  \refstepcounter{chapter}%
  \addtocontents{\csname ext@toc\endcsname}{\protect\value{tocdepth}=\chaptertocdepth}%
}{}{}

Background: The KOMA-Script classes and packages also use \ext@toc instead of hard-coded toc. This, e.g., can be used to write the entries of the appendix into a separate ToC:

\documentclass[listof=totoc]{scrreprt}% oneside is default
\usepackage[toc,nonumberlist]{glossaries}
\makeglossaries

\usepackage{xpatch}
\makeatletter
\xapptocmd{\appendix}{%
  \addchap{Appendix}%
  \refstepcounter{chapter}%
  \renewcommand*{\ext@toc}{atoc}%
  \section*{Contents}% OPTIONAL
  \listoftoc*{atoc}% OPTIONAL
}{}{}
\makeatother
\DeclareNewTOC{atoc}%

\begin{document}
\tableofcontents
\listoffigures
\chapter{Chapter One}
\section{Section One}
\chapter{Chapter Two}
\section{Section One}
\begin{figure}[h]
\caption{A Caption}
\end{figure}

\appendix
\section{test 1}
Text
\section{test 2}

\end{document}

If you comment out the two lines marked with OPTIONAL, you would have another solution for your question.

0

I fixed the empty list of figures after esdd's suggestion by adding

\setcounter{tocdepth}{2} 

between the toc and list of figures.

This is the final working code, thanks for the help!

\documentclass[listof=totoc,oneside]{scrreprt}  
\usepackage[toc,nonumberlist]{glossaries}
\makeglossaries

\begin{document}
\tableofcontents
\setcounter{tocdepth}{2}
\listoffigures
\chapter{Chapter One}
\section{Section One}
\chapter{Chapter Two}
\section{Section One}
\begin{figure}[h]
\caption{A Caption}
\end{figure}

\appendix
\addchap{Appendix}\addtocontents{toc}{\setcounter{tocdepth}{0}}
\renewcommand*{\thesection}{A.\arabic{section}}
\section{test 1}
Text
\section{test 2}

\end{document}
  • 1
    You should prefer a solution that does the whole setup in the document preamble. And your solution needs knowledge about the preamble setting of tocdepth in the document body. This could easily break, if you change such a setting in the preamble or if you change the class. esdd used \BeforeStartingTOC and \AfterStartingTOC to avoid such problems. – Schweinebacke May 9 '17 at 12:13

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.