1

I have a problem with the placement of Appendix titles in the TOC. I use the appendix package with titletoc option. The following code

\documentclass{scrreprt}

\usepackage[utf8]{inputenc}
\usepackage[title,titletoc]{appendix} 

\begin{document}

\tableofcontents 

\chapter{some chapter}

\begin{subappendices}

\section{Short title}
\section{This is a very long title that reaches the right end of the separable}
\section{Long title}

\end{subappendices}

\chapter{some other chapter}

\begin{subappendices}
\section{short title in only 1 line}
\section{much longer title that will be displayed over two lines rather than just 1}
\section{short title in only 1 line}
\end{subappendices}

\end{document}       

produces the following TOC:

enter image description here

As you can see, the 1.A, 1.B and 1.C are not aligned (possibly because of the word "separable" which is too long. Similar things happen for the second block, where 2.B is not aligned.

How can I fix this apart from changing the titles?

2

Here is a suggestion without package appendix.

The section command \section is in scrreprt declared as

\DeclareSectionCommand[%
  style=section,%
  level=1,%
  indent=\z@,%
  beforeskip=-3.5ex \@plus -1ex \@minus -.2ex,%
  afterskip=2.3ex \@plus.2ex,%
  tocstyle=section,%
  tocindent=1.5em,%
  tocnumwidth=2.3em%
]{section}

You can declare a new section command on the same level as \section but with a different tocnumwidth.

    \documentclass[numbers=noenddot]{scrreprt}
    \usepackage[utf8]{inputenc}

    \DeclareNewSectionCommand[
        style=section,
        level=1,
        indent=0pt,
        beforeskip=-3.5ex plus -1ex minus -.2ex,
        afterskip=2.3ex plus .2ex,
        tocindent=1.5em,
        tocnumwidth=7em,
        counterwithin=chapter,
        font=\usekomafont{section},
    ]{subappendix}

    \makeatletter
    \AtBeginDocument{\let\toclevel@subappendix\toclevel@section}
    \makeatother

    \renewcommand\thesubappendix{\thechapter.\Alph{subappendix}}
    \renewcommand\subappendixformat{\appendixname~\thesubappendix\autodot\quad}
    \renewcommand\addsubappendixtocentry[2]{%
        \addtocentrydefault{subappendix}{\appendixname~#1}{#2}%
    }

    \newenvironment{subappendices}{\let\section\subappendix}{}

    \begin{document}
    \tableofcontents 
    \chapter{some chapter}
    \begin{subappendices}
        \section{Short title}
        \section{This is a very long title that reaches the right end of the separable}
        \section{Long title}
    \end{subappendices}

    \chapter{some other chapter}
    \begin{subappendices}
        \section{short title in only 1 line}
        \section{much longer title that will be displayed over two lines rather than just 1}
        \section{short title in only 1 line}
    \end{subappendices}

    \chapter{some other chapter}
    \subappendix{short title in only 1 line}
    \subappendix{much longer title that will be displayed over two lines rather than just 1}
    \subappendix{short title in only 1 line}
    \end{document}  

Result:

enter image description here

  • Sorry, but this solution does not work for me. I get an "! Undefined control sequence. l.4 \DeclareNewSectionCommand" error. Potentially, my KOMA script version is too old? – user3825755 Mar 29 '16 at 13:46
  • Which KOMA-Script version do you use? Current version on CTAN is 3.19a. I have tested the code with version 3.16 [2015/02/07] too. AFAIR command \DeclareNewSectionCommand was indroduced in version 3.15. – esdd Mar 29 '16 at 14:57
  • That probably exlpains the issues. Apparently I am using version 3.12. As this is part of my PhD thesis which is near completion, I am somewhat reluctant to update the KOMA script version right now as I am afraid that things will break. – user3825755 Mar 29 '16 at 15:04

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.