1

I searched some information on horizontal lines and spacing in other questions posted about TOC's, but could not reproduce what I wanted. Furthermore I get some badboxes adjusting horizontal spaces in my TOC.

When insert a horizontal space for subsections using the tocnumwidth I get a underfull \hbox. Does anybody know how to get rid of the badboxes?

\RedeclareSectionCommands[tocnumwidth=10pt,tocindent=0pt,tocentrynumberformat=\intoleftmargin]{subsection,subsubsection}

Furthermore I would like to know how to insert horizontal lines under chapters,section and subsections to style my TOC?

Below my full MWE. Thanks in advance!!

\documentclass{scrreprt}

\usepackage[
includemp,
                  showframe,
                  reversemp,
            paperwidth=20.1cm,
            paperheight=25.80cm,
            top=2.30cm,
            bottom=3.4cm,
            inner=2.7cm,
            outer=2.7cm,
            marginparwidth=1.6cm, % Fixed for now
            marginparsep=0.4cm
            ]{geometry}

\usepackage{etoolbox} %control vspave in ToC
\usepackage{lipsum}
\usepackage[footwidth=textwithmarginpar]{scrlayer-scrpage}
% \usepackage{tocstyle}

\makeatletter          % to set the marginpar on the left side in showframe
\let\Gm@vrules@mpi\Gm@vrules@mpii
\makeatother

%-------------------- CHAPTER HEADINGS and TOC -----------

\renewcommand*{\chapterformat}{\intoleftmargin{\chapappifchapterprefix{\ 
}\thechapter\autodot}}%
\renewcommand*{\sectionformat}{\intoleftmargin{\thesection\autodot}}
\renewcommand*{\subsectionformat}{\intoleftmargin{\thesubsection\autodot}}
\renewcommand*{\subsubsectionformat}
{\intoleftmargin{\thesubsubsection\autodot}}

% remove the vertical skip before the chapter heading
\RedeclareSectionCommand[beforeskip=-1sp plus -1sp minus 1sp]{chapter}
\RedeclareSectionCommands[tocnumwidth=0pt,tocindent=0pt,tocentrynumberformat=\intoleftmargin]{chapter,section}
\RedeclareSectionCommands[tocnumwidth=10pt,tocindent=0pt,tocentrynumberformat=\intoleftmargin]{subsection,subsubsection}
\newcommand*{\intoleftmargin}[1]{\makebox[0pt][r]{#1\hskip\marginparsep}}

\makeatletter
\renewcommand{\@dotsep}{10000} 
\makeatother

\makeatletter
\pretocmd{\chapter}{\addtocontents{toc}{\protect\addvspace{15\p@}}}{}{}
\pretocmd{\section}{\addtocontents{toc}{\protect\addvspace{5\p@}}}{}{}
\pretocmd{\subsection}{\addtocontents{toc}{\protect\addvspace{2\p@}}}{}{}
\makeatother

%---------------------------------------------------------

%---------------------------PAGE STYLE--------------------

\clearpairofpagestyles
\automark{chapter}
\ifoot{%
  \makebox[0pt][r]{\pagemark\autodot\hskip\marginparsep}%
  \ifodd \value{page}%
    Quantifying goodness of morphodynamic field predictions
  \else
    \headmark %
  \fi
}
\setkomafont{pageheadfoot}{\normalfont}
\renewcommand\chaptermarkformat{}

\renewcommand*\chapterpagestyle{scrheadings}

%---------------------------------------------------------

\begin{document}


\tableofcontents


\chapter{chapter}
\section{section}
\section{section}
\section{section}
\subsection{subsection}

\chapter{chapter}
\section{section}
\subsection{subsection}

\chapter{chapter}
\section{section}
\subsection{subsection}

\chapter*{section}
\addcontentsline{toc}{section}{section}

\end{document}

enter image description here

0

1 Answer 1

2

The following does what you ask (but I neither know whether it's the right way to do it nor whether it's the right thing to do):

\documentclass{scrreprt}

% packages>>>
\usepackage[%>>>geometry
includemp,
                  showframe,
                  reversemp,
            paperwidth=20.1cm,
            paperheight=25.80cm,
            top=2.30cm,
            bottom=3.4cm,
            inner=2.7cm,
            outer=2.7cm,
            marginparwidth=1.6cm, % Fixed for now
            marginparsep=0.4cm
            ]{geometry}%<<<
\usepackage{etoolbox} %control vspave in ToC
\usepackage{lipsum}
\usepackage[footwidth=textwithmarginpar]{scrlayer-scrpage}
% \usepackage{tocstyle}
%<<<

\makeatletter          % to set the marginpar on the left side in showframe
\let\Gm@vrules@mpi\Gm@vrules@mpii
\makeatother

%-------------------- CHAPTER HEADINGS and TOC ----------->>>

\renewcommand*{\chapterformat}{\intoleftmargin{\chapappifchapterprefix{\ 
}\thechapter\autodot}}%
\renewcommand*{\sectionformat}{\intoleftmargin{\thesection\autodot}}
\renewcommand*{\subsectionformat}{\intoleftmargin{\thesubsection\autodot}}
\renewcommand*{\subsubsectionformat}
{\intoleftmargin{\thesubsubsection\autodot}}

% remove the vertical skip before the chapter heading
\RedeclareSectionCommand[beforeskip=-1sp plus -1sp minus 1sp]{chapter}
\RedeclareSectionCommands[tocnumwidth=0pt,tocindent=0pt,tocentrynumberformat=\intoleftmargin,tocentryformat=\lineundertocchap]{chapter}
\RedeclareSectionCommands[tocnumwidth=0pt,tocindent=0pt,tocentrynumberformat=\intoleftmargin,tocentryformat=\lineundertocsec]{section}
\RedeclareSectionCommands[tocnumwidth=10pt,tocindent=0pt,tocentrynumberformat=\intoleftmargin,tocentryformat=\lineundertocsec]{subsection,subsubsection}
\newcommand*{\intoleftmargin}[1]{\makebox[0pt][r]{#1\hskip\marginparsep}\hfill}
\newcommand*{\lineundertocsec}[1]{%
    \ifunderlinetoc%
        \raisebox{-4pt}{\makebox[0pt][l]{\rule{\linewidth}{0.5pt}}}%
    \fi#1}
\newcommand*{\lineundertocchap}[1]{%
    \ifunderlinetoc%
        \raisebox{-4pt}{\makebox[0pt][l]{\rule{\linewidth}{1pt}}}%
    \fi\sffamily\bfseries#1}
\newif\ifunderlinetoc\underlinetoctrue

\makeatletter
\renewcommand{\@dotsep}{10000} 
\makeatother

\makeatletter
\pretocmd{\chapter}{\addtocontents{toc}{\protect\addvspace{15\p@}}}{}{}
\pretocmd{\section}{\addtocontents{toc}{\protect\addvspace{5\p@}}}{}{}
\pretocmd{\subsection}{\addtocontents{toc}{\protect\addvspace{2\p@}}}{}{}
\makeatother

%---------------------------------------------------------<<<

%---------------------------PAGE STYLE-------------------->>>

\clearpairofpagestyles
\automark{chapter}
\ifoot{%
  \makebox[0pt][r]{\pagemark\autodot\hskip\marginparsep}%
  \ifodd \value{page}%
    Quantifying goodness of morphodynamic field predictions
  \else
    \headmark %
  \fi
}
\setkomafont{pageheadfoot}{\normalfont}
\renewcommand\chaptermarkformat{}

\renewcommand*\chapterpagestyle{scrheadings}

%---------------------------------------------------------<<<

\begin{document}


\tableofcontents

\addtocontents{toc}{\protect\underlinetocfalse}
\chapter{chapter}
\addtocontents{toc}{\protect\underlinetoctrue}
\section{section}
\section{section}
\section{section}
\subsection{subsection}
\subsubsection{subsection}

\chapter{chapter}
\section{section}
\subsection{subsection}
\subsubsection{subsection}

\chapter{chapter}
\section{section}
\subsection{subsection}
\subsubsection{subsection}

\chapter*{section}
\addcontentsline{toc}{section}{section}

\end{document}

enter image description here

2
  • Thank you! thats indeed what I want. However if I want to cancel the new defined command. For instance I want to cancel for a particular section the underline, what kind of comment should I place in the section?
    – SLeenders
    Aug 15, 2017 at 13:12
  • @SLeenders see my edit in which I disabled the underlining of the first chapter in TOC.
    – Skillmon
    Aug 15, 2017 at 14:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .