1

How do I un-indent the second line of a large entry in the table of contents with tocstyle tocline on the KOMA Script class scrartcl? I found the same question here: ToC: How to no-indent the second line of large entries? but for tocloft, and the answer doesn't seem to work.

EDIT: Added the MWE. I'm using custom sectioning commands described here: Custom document structure.

\documentclass{scrartcl}

\linespread{1.1}
\setlength{\parindent}{0.5cm}

\usepackage{lipsum}

\newcommand\entryprefix[2]{%
  #1\ #2
}

\DeclareNewSectionCommand[
  style=section,
  level=\subsubsectionnumdepth,
  beforeskip=3.25ex plus 1ex minus .2ex,
  afterskip= 1.5ex plus .2ex,
  indent=0pt,
  font=\mdseries\slshape,
  %tocstyle=gobble,
  tocstyle=default,
  toclevel=\subsubsectiontocdepth,
  tocindent=4em,
  tocnumwidth=2.3em,
  tocdynnumwidth,
  tocentrynumberformat=\entryprefix{Article}
]{Article}
\renewcommand\Articleformat{Article~\theArticle\autodot\enskip}

\renewcommand\sectionlinesformat[4]{%
  \ifstr{#1}{Article}
    {\raggedright\textbf{\upshape#3}#4.}
    {#3#4}%
}

\begin{document}

\tableofcontents

\lipsum[1-2]

\Article{Short title}

\lipsum[3]

\Article{Very long article title that (on the Table of Contents) should start on the beginning of the line instead of at the beginning of the word Article}

\lipsum[4]

\end{document}
  • 2
    You can make your question much easier to answer by providing an MWE. An MWE makes sure that we are all talking about the same thing and that we can test our solutions with your actual set-up. An MWE also helps us to get started more quickly because we won't have to rebuild what you already have. There are many KOMA options that could influence the TOC and it would really help if you could show us your setup so we don't have to speculate and resort to guessing. – moewe Jun 9 '18 at 20:30
  • I'm so sorry. I've been doing my finals and I've been very very busy. I've updated the post with an MWE. – José María Jun 26 '18 at 16:59
3

Update

Now there is a MWE in the question and I understand that you need the change (only?) for your custom sectionning command \Article. You can simple adapt the solution from the original answer below:

\documentclass{scrartcl}
\linespread{1.1}
\setlength{\parindent}{0.5cm}
\usepackage{lipsum}% only for dummy text

\DeclareNewSectionCommand[
  style=section,
  level=\subsubsectionnumdepth,
  beforeskip=3.25ex plus 1ex minus .2ex,
  afterskip= 1.5ex plus .2ex,
  indent=0pt,
  font=\mdseries\slshape,
  %tocstyle=gobble,
  tocstyle=default,
  toclevel=\subsubsectiontocdepth,
  tocindent=4em,
  tocnumwidth=0pt% <- changed to 0pt, tocdynnumwidth and tocentrynumberformat are removed
]{Article}
\renewcommand\Articleformat{Article~\theArticle\autodot\enskip}

\renewcommand*\addArticletocentry[2]{%
  \addtocentrydefault{Article}{}
    {\IfArgIsEmpty{#1}{}{Article~\makebox[1.5em][l]{#1\protect\autodot}}#2}%
}% maybe you have to adjust the 1.5em -> run twice to see the change in TOC

\renewcommand\sectionlinesformat[4]{%
  \ifstr{#1}{Article}
    {\raggedright\textbf{\upshape#3}#4.}
    {#3#4}%
}

\begin{document}
\tableofcontents
\lipsum[1-2]
\Article{Short title}
\lipsum[3]
\Article{Very long article title that (on the Table of Contents) should start on the beginning of the line instead of at the beginning of the word Article}
\lipsum[4]
\end{document}

Result:

enter image description here

But maybe you want:

enter image description here

\DeclareNewSectionCommand[
  style=section,
  level=\subsubsectionnumdepth,
  beforeskip=3.25ex plus 1ex minus .2ex,
  afterskip= 1.5ex plus .2ex,
  indent=0pt,
  font=\mdseries\slshape,
  %tocstyle=gobble,
  tocstyle=default,
  toclevel=\subsubsectiontocdepth,
  tocindent=0pt,% <- changed
  tocnumwidth=0pt% <- changed to 0pt, tocdynnumwidth and tocentrynumberformat are removed
]{Article}
\renewcommand\Articleformat{Article~\theArticle\autodot\enskip}

\renewcommand*\addArticletocentry[2]{% <- definition changed
  \addtocentrydefault{Article}{}
    {\IfArgIsEmpty{#1}{}{\hspace{4em}Article~\makebox[1.5em][l]{#1\protect\autodot}}#2}%
}% maybe you have to adjust the 1.5em -> run twice to see the change in TOC

Or:

enter image description here

\DeclareNewSectionCommand[
  style=section,
  level=\subsubsectionnumdepth,
  beforeskip=3.25ex plus 1ex minus .2ex,
  afterskip= 1.5ex plus .2ex,
  indent=0pt,
  font=\mdseries\slshape,
  %tocstyle=gobble,
  tocstyle=default,
  toclevel=\subsubsectiontocdepth,
  tocindent=0pt,
  tocnumwidth=0pt
]{Article}
\renewcommand\Articleformat{Article~\theArticle\autodot\enskip}

\renewcommand*\addArticletocentry[2]{% <-definition changed
  \addtocentrydefault{Article}{}
    {\IfArgIsEmpty{#1}{}{Article~\makebox[1.5em][l]{#1\protect\autodot}}#2}%
}% maybe you have to adjust the 1.5em -> run twice to see the change in TOC

Original answer

Unfortunaly there is no MWE in the question, so its only a guess:

\documentclass{scrartcl}
\RedeclareSectionCommands[%
  tocnumwidth=0pt%
]{section,subsection,subsubsection,paragraph,subparagraph}

\renewcommand*\addsectiontocentry[2]{%
  \addtocentrydefault{section}{}
    {\IfArgIsEmpty{#1}{}{\makebox[1.5em][l]{#1\protect\autodot}}#2}%
}
\renewcommand*\addsubsectiontocentry[2]{%
  \addtocentrydefault{subsection}{}
    {\IfArgIsEmpty{#1}{}{\makebox[2.3em][l]{#1\protect\autodot}}#2}%
}
\renewcommand*\addsubsubsectiontocentry[2]{%
  \addtocentrydefault{subsubsection}{}
    {\IfArgIsEmpty{#1}{}{\makebox[3.8em][l]{#1\protect\autodot}}#2}%
}
\renewcommand*\addparagraphtocentry[2]{%
  \addtocentrydefault{paragraph}{}
    {\IfArgIsEmpty{#1}{}{\makebox[4.1em][l]{#1\protect\autodot}}#2}%
}
\renewcommand*\addsubparagraphtocentry[2]{%
  \addtocentrydefault{subparagraph}{}
    {\IfArgIsEmpty{#1}{}{\makebox[5em][l]{#1\protect\autodot}}#2}%
}

\usepackage{lipsum}% only for dummy text
\begin{document}
\tableofcontents
\clearpage
\addsec{Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.}
\lipsum[1-5]
\section{Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.}
\lipsum[6]
\subsection{Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.}
\lipsum[7-10]
\subsection{Lorem ipsum dolor sit amet, consectetuer adipiscing elit.}
\lipsum[11-15]
\end{document}

enter image description here

  • Hi. I'm very sorry. I've been doing my finals and I didn't have time to improve this question. I've edited the question with an MWE. I'm using custom sectioning commands (something that I should've specified) so your answer does not work because the commands I'm using dynamically change the width of the counter. You can take a look at the MWE. Thanks for your help. – José María Jun 26 '18 at 17:01
  • 1
    See my updated answer. Note that the missing MWE has wasted my time. I am busy too. You have to adjusted the needed space for "Article <number>" manually. If you change the width of the boxes then run twice to see the result in TOC. – esdd Jun 27 '18 at 9:42
  • Thank you! The second one is what I wanted. One more question, is it possible to have it adjust the width of the "tocnumwidth" automatically? I have other type of entries "Disposición adicional primera|segunda|tercera" that changes width and would like to have a similar effect. If it's not possible I can set it up with a fixed witdh. – José María Jun 28 '18 at 11:06
  • I have updated my answer. Now \makebox is used for the entry number only: Article~\makebox[1.5em][l]{#1\protect\autodot}}#2. You only have to adjust the width of this box if there are numbers with three or more digits. – esdd Jun 29 '18 at 9:06
  • So, as I understand, there's no way for that width to be adjusted automatically, right? Right now the width is the same whether the number has 1 or 3 digits, which makes the lines with 1 digit look a bit ood (the're spaced too much from the number). Still, thanks for your patience and help :) – José María Jul 1 '18 at 16:57

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.