2

I would like to display the appendix chapter title as "Appendix A Appendixname" in the table of contents and "A Appendixname" in the text.

So far i get the right order of "A" and "Appendix" using \usepackage[titletoc]{appendix} but an unwanted dot gets printed (i.e. "Appendix A. Appendixname) in the toc.

Previously, one could alter appendix titleformats using the \appendixmore-trick, however this functionality seems to be depreached as of KOMA-Script 3.34 (see changelog). Unfortunately i don't know enough LaTEX to find a new solution with the information presented in the changelog.

My current code:

\documentclass{scrreprt}
\usepackage[titletoc]{appendix}

% appendixmore-trick (not working anymore) \newcommand{\appendixmore}{% \renewcommand{\sectionformat}{\appendixname~\thesection\autodot\enskip} \renewcommand*{\sectionmarkformat}{\appendixname~\thesection\autodot\enskip} }

\begin{document}

\tableofcontents

\chapter{Lorem ipsum} \section{Dolor sit amet}

\appendix

\begin{appendices} \chapter{Consectetur adipiscing elit} \chapter{Mauris euismod} \end{appendices} \end{document}

This works apart from the unwanted dots:

toc with unwanted dot after "A"

Same for the chapter title:

title with unwanted dot after "A"

Any help is appreciated :)

2 Answers2

1

Your definition of \appendixmore will works with KOMA-Script version 3.34, too.

If LaTeX as of version 2021/06/01 is used with a KOMA-Script class

From changelog of version 3.34

  • \appendix contains a LaTeX hook named <class>/appendix, where <class> is the name of the KOMA-Script class.
  • This hook is executed before \appendixmore.
  • Option appendixprefix (and headings=onelineappendix and headings=twolineappendix) is no longer implemented via \appendixmore, but via the LaTeX hook <class>/appendix.

So a user defined \appendixmore will be executed with KOMA-Script version 3.34, too. Additionally you can use \newcommand\appendixmore{...} even if you use one of the options appendixprefix, headings=onelineappendix or headings=twolineappendix.

Example:

\documentclass
  [appendixprefix=false]
  {scrreprt}

\newcommand{\appendixmore}{\renewcommand{\chapterformat}{This is \appendixname:\enskip}} \begin{document} \chapter{Foo} \appendix \chapter{Bar} \KOMAScriptVersion \end{document}

works with an uptodate KOMA-Script prerelease of version 3.34 and LaTeX as of version 2021/06/01. But with KOMA-Script version 3.33 or older you would get the error message »Command \appendixmore already defined.«, because the old KOMA-Script versions have defined this macro to implement the options appendixprefix etc.


The following example can be used with KOMA-Script version 3.33 or version 3.34. It removes the dot only from appendix chapters numbering and adds the prefix in ToC without an additional package:

\documentclass{scrreprt}

\newcommand{\appendixmore}{ \renewcommand{\chapterformat}{\thechapter\enskip}% \renewcommand*{\chaptermarkformat}{\thechapter\enskip}% \addtocontents{toc}{\protect\appendixtocentry}% }

\newcommand*{\appendixtocentry}{% \DeclareTOCStyleEntry[ entrynumberformat=\appendixprefixfixintoc, dynnumwidth ]{default}{chapter}% } \newcommand{\appendixprefixfixintoc}[1]{% \def\autodot{}% \appendixname~#1% }

\begin{document} \tableofcontents

\KOMAScriptVersion

\chapter{Lorem ipsum} \section{Dolor sit amet}

\appendix \chapter{Consectetur adipiscing elit, Consectetur adipiscing elit, Consectetur adipiscing elit} \chapter{Mauris euismod} \end{document}

Run three times to get

enter image description here

It is also possible to use the new hook provided by KOMA-Script version 3.34:

\documentclass{scrreprt}[2021-04-30]

\AddToHook{scrreprt/appendix}{% \AddToHook{cmd/chapterformat/before}{\def\autodot{}}% \AddToHook{cmd/chaptermarkformat/before}{\def\autodot{}}% \addtocontents{toc}{\appendixtocentry}% }

\NewDocumentCommand{\appendixtocentry}{}{% \DeclareTOCStyleEntry[ entrynumberformat=\appendixprefixfixintoc, dynnumwidth ]{default}{chapter}% } \NewDocumentCommand{\appendixprefixfixintoc}{m}{% \def\autodot{}% \appendixname~#1% }

\begin{document} \tableofcontents

\KOMAScriptVersion

\chapter{Lorem ipsum} \section{Dolor sit amet}

\appendix \chapter{Consectetur adipiscing elit, Consectetur adipiscing elit, Consectetur adipiscing elit} \chapter{Mauris euismod} \end{document}

But may be it is better to use a generic hook of command \appendix: cmd/appendix/after. It is executed at the very end of the command body of \appendix. Note \appendixmore - if defined - would be executed before this hook.

\documentclass{scrreprt}[2021-04-30]

\AddToHook{cmd/appendix/after}{% \AddToHook{cmd/chapterformat/before}{\def\autodot{}}% \AddToHook{cmd/chaptermarkformat/before}{\def\autodot{}}% \addtocontents{toc}{\appendixtocentry}% }

\NewDocumentCommand{\appendixtocentry}{}{% \DeclareTOCStyleEntry[ entrynumberformat=\appendixprefixfixintoc, dynnumwidth ]{default}{chapter}% } \NewDocumentCommand{\appendixprefixfixintoc}{m}{% \def\autodot{}% \appendixname~#1% }

\begin{document} \tableofcontents

\KOMAScriptVersion

\chapter{Lorem ipsum} \section{Dolor sit amet}

\appendix \chapter{Consectetur adipiscing elit, Consectetur adipiscing elit, Consectetur adipiscing elit} \chapter{Mauris euismod} \end{document}

The result is the same as above.

esdd
  • 85,675
0

I found an answer to the problem:

Use the numbers=noenddot option of scrreprt to prevent trailing dots in the toc. In contrary to my initial plan, this removes all trailing dots throughout the numbering sceme of the document but i am actually happy with this.

\documentclass[numbers=noenddot]{scrreprt}

Secondly, as linked by schtandard, the format of the chapter title can be changed by overwriting \chapterformat right before the appendix. (See also KOMA-Script scrbook: How to remove period after part)

\renewcommand*{\chapterformat}{\appendixname~\thechapter~~}

Remember to change the command back to its original form if you want the following sections to be displayed in the usual way.