3

Using the scrreprt class of KOMA-Script with xelatex, I'd like to have my section entries in the table of contents appear without indenting. My current code is:

\documentclass[10pt,a5paper,DIV12,BCOR8.25mm,twoside,parskip=half]{scrreprt}
% setup the table of contents
\usepackage[tocbreaksstrict]{tocstyle}
\usetocstyle{standard}
\settocfeature{raggedhook}{\raggedright}
\makeatletter
\renewcommand{\@pnumwidth}{3em}
\renewcommand{\@tocrmarg}{4em}
\makeatother
\KOMAoptions{toc=flat} 
\setcounter{secnumdepth}{0}
\begin{document}
\tableofcontents
\section{First Section}
\section{Second Section}
\end{document}

which results in the following output:

Section heading normal toc

However, I'd like to have the lines in the toc flush left with the rest.

Ideally, this would work with tocstyle, which most probably prohibits the use of tocloft to do this. The reason I'm using tocstyle is that it seems to get me best results in typesetting a very large table of contents of a ~2000 pages book with hundreds of sections. Many section titles used to extend into the right margin and push out the page numbers. This seems to be largely fixed by the two \renewcommand settings. However, I also needed the \raggedright to avoid the toc to be set in funny looking justified style. That's when tocstyle came into the game.

If there is need to change over to tocloft, I'm happy to do that provided it works with my long section titles not shown in the example above.

2

Try this:

\makeatletter
\renewcommand*\l@section{\bprot@dottedtocline{1}{0em}{2.3em}}% no indentation
\renewcommand{\@pnumwidth}{3em}
\renewcommand{\@tocrmarg}{4em}
\makeatother
  • beautiful, spot on! – kongo09 Oct 21 '11 at 9:33
  • Note, the redefinition of \l@section is not longer recommended. – Schweinebacke Jun 21 '17 at 6:27
1

The (key-value) KOMA option toc=flat is currently not recognized by tocstyle. Replace it with the tocstyle package option tocflat.

\documentclass[10pt,a5paper,DIV12,BCOR8.25mm,twoside,parskip=half]{scrreprt}
% setup the table of contents
\usepackage[tocbreaksstrict,tocflat]{tocstyle}
\usetocstyle{standard}
\settocfeature{raggedhook}{\raggedright}
\makeatletter
\renewcommand{\@pnumwidth}{3em}
\renewcommand{\@tocrmarg}{4em}
\makeatother
% \KOMAoptions{toc=flat} 
\setcounter{secnumdepth}{0}
\begin{document}
\tableofcontents
\section{First Section}
\section{Second Section}
\end{document}
1

With an uptodate KOMA-Script version there is no need to load an additional package to use \raggedright for the section entries in ToC. This can be done by

\RedeclareSectionCommand[tocraggedentrytext]{section}

enter image description here

Code:

\documentclass[10pt,a5paper,
  DIV=12,BCOR=8.25mm,% syntax has changed
  twoside,parskip=half,
  toc=flat
]{scrreprt}
\RedeclareSectionCommand[tocraggedentrytext]{section}

\makeatletter
\renewcommand{\@pnumwidth}{3em}
\renewcommand{\@tocrmarg}{4em}
\makeatother

\setcounter{secnumdepth}{0}
\begin{document}
\tableofcontents
\section{First Section}
Text
\section{Second Section}
Text
\section{Third Section with a long title that needs more than one line in the table of contents}
Text
\end{document}

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.