1

Is there a way to make the indent of chapter and section so that the title of both starts math the same width? For the example: E of Einleitung and Z of Zielstellung directly aligned.

I am using this KOMA-class:

\documentclass[12pt, numbers=noenddot,parskip,headings=small,headsepline,listof=nochaptergap, listof=totoc,index=totoc]{scrreprt}
\usepackage[a4paper, includehead, left=3.5cm, right=1.7cm, top=2.5cm, bottom=2.0cm]{geometry}
\RedeclareSectionCommand[
beforeskip=-1sp,
afterskip=.25\baselineskip]{chapter}
\RedeclareSectionCommand[
beforeskip=-\baselineskip,
afterskip=.5\baselineskip]{section}
\RedeclareSectionCommand[
beforeskip=-.75\baselineskip,
afterskip=.5\baselineskip]{subsection}
\RedeclareSectionCommand[
beforeskip=-.5\baselineskip,
afterskip=.25\baselineskip]{subsubsection}
\RedeclareSectionCommand[
beforeskip=.5\baselineskip,
afterskip=-1em]{paragraph}
\RedeclareSectionCommand[
beforeskip=-.5\baselineskip,
afterskip=-1em]{subparagraph}

\begin{document}
\chapter{Einleitung}
\section{Zielstellung}
\end{document}

Indent for Section Heading

2

You can put the numbers in a box of the same width. Note that you cannot use em or ex here, because this would depend on the font sizes of the headings and therefore only be the same if the font sizes of all sectioning levels are the same, e.g.,

\newcommand*{\chapterformat}{%
  \IfChapterUsePrefixLine{\chapapp\nobreakspace\thechapter\autodot}{%
    \makebox[40pt][l]{\thechapter\autodot\hfil}%
  }%
}
\newcommand*{\sectionformat}{\makebox[40pt][l]{\thesection\autodot\hfil}}

This can be extended for all levels, but in this case 40pt are not enough:

\renewcommand*{\chapterformat}{%
  \IfUsePrefixLine{\chapapp\nobreakspace\thechapter\autodot}{%
    \makebox[80pt][l]{\thechapter\autodot\hfil}%
  }%
}
\renewcommand*{\sectionformat}{\makebox[80pt][l]{\thesection\autodot\hfil}}
\renewcommand*{\subsectionformat}{\makebox[80pt][l]{\thesubsection\autodot\hfil}}
\renewcommand*{\subsubsectionformat}{\makebox[80pt][l]{\thesubsubsection\autodot\hfil}}
\renewcommand*{\paragraphformat}{\makebox[80pt][l]{\theparagraph\autodot\hfil}}
\renewcommand*{\subparagraphformat}{\makebox[80pt][l]{\thesubparagraph\autodot\hfil}}

But if (and only if) you want the same indent for all levels from chapter down to subparagraph you could also redefine \chapterlinesformat, \sectionlinesformat and \sectioncatchphraseformat:

\documentclass[12pt, numbers=noenddot,parskip,headings=small,headsepline,listof=nochaptergap, listof=totoc,index=totoc]{scrreprt}
\usepackage[a4paper, includehead, left=3.5cm, right=1.7cm, top=2.5cm, bottom=2.0cm]{geometry}
\RedeclareSectionCommand[
beforeskip=-1sp,
afterskip=.25\baselineskip]{chapter}
\RedeclareSectionCommand[
beforeskip=-\baselineskip,
afterskip=.5\baselineskip]{section}
\RedeclareSectionCommand[
beforeskip=-.75\baselineskip,
afterskip=.5\baselineskip]{subsection}
\RedeclareSectionCommand[
beforeskip=-.5\baselineskip,
afterskip=.25\baselineskip]{subsubsection}
\RedeclareSectionCommand[
beforeskip=.5\baselineskip,
afterskip=-1em]{paragraph}
\RedeclareSectionCommand[
beforeskip=-.5\baselineskip,
afterskip=-1em]{subparagraph}

\newlength{\allsectionnumberwidth}
\setlength{\allsectionnumberwidth}{80pt}
\makeatletter
\renewcommand{\chapterlinesformat}[3]{%
  \IfArgIsEmpty{#2}{#3}{%
    \@hangfrom{\makebox[\allsectionnumberwidth][l]{#2}}{#3}%
  }%
}
\renewcommand{\sectionlinesformat}[4]{%
  \IfArgIsEmpty{#3}{\@hangfrom{\hskip #2}{#4}}{%
    \@hangfrom{\makebox[\allsectionnumberwidth][l]{\hskip #2#3}}{#4}%
  }%
}
\renewcommand{\sectioncatchphraseformat}[4]{%
  \IfArgIsEmpty{#3}{\hskip #2#3#4}{%
    \makebox[\allsectionnumberwidth][l]{\hskip #2#3}#4%
  }%
}
\makeatother

\setcounter{secnumdepth}{\subparagraphnumdepth}% To show it for all levels

\begin{document}
\chapter{Chapter Heading}
\section{Section Heading}
\subsection{Subsection Heading}
\subsubsection{Subsubsection Heading}
\paragraph{Paragraph Heading}
\subparagraph{Subparagraph Heading}
\end{document}

You even could detect the needed number width automatically:

\documentclass[12pt, numbers=noenddot,parskip,headings=small,headsepline,listof=nochaptergap, listof=totoc,index=totoc]{scrreprt}
\usepackage[a4paper, includehead, left=3.5cm, right=1.7cm, top=2.5cm, bottom=2.0cm]{geometry}
\RedeclareSectionCommand[
beforeskip=-1sp,
afterskip=.25\baselineskip]{chapter}
\RedeclareSectionCommand[
beforeskip=-\baselineskip,
afterskip=.5\baselineskip]{section}
\RedeclareSectionCommand[
beforeskip=-.75\baselineskip,
afterskip=.5\baselineskip]{subsection}
\RedeclareSectionCommand[
beforeskip=-.5\baselineskip,
afterskip=.25\baselineskip]{subsubsection}
\RedeclareSectionCommand[
beforeskip=.5\baselineskip,
afterskip=-1em]{paragraph}
\RedeclareSectionCommand[
beforeskip=-.5\baselineskip,
afterskip=-1em]{subparagraph}

\newlength{\allsectionnumberwidth}
\setlength{\allsectionnumberwidth}{40pt}% use at least 40pt
\newlength{\maxallsectionnumberwidth}
\setlength{\maxallsectionnumberwidth}{\allsectionnumberwidth}
\makeatletter
\renewcommand{\chapterlinesformat}[3]{%
  \IfArgIsEmpty{#2}{#3}{%
    \updateallsectionnumberwidth{#2}%
    \@hangfrom{\makebox[\allsectionnumberwidth][l]{#2}}{#3}%
  }%
}
\renewcommand{\sectionlinesformat}[4]{%
  \IfArgIsEmpty{#3}{\@hangfrom{\hskip #2}{#4}}{%
    \updateallsectionnumberwidth{\hskip #2#3}%
    \@hangfrom{\makebox[\allsectionnumberwidth][l]{\hskip #2#3}}{#4}%
  }%
}
\renewcommand{\sectioncatchphraseformat}[4]{%
  \IfArgIsEmpty{#3}{\hskip #2#3#4}{%
    \updateallsectionnumberwidth{\hskip #2#3}%
    \makebox[\allsectionnumberwidth][l]{\hskip #2#3}#4%
  }%
}
\newcommand*{\updateallsectionnumberwidth}[1]{%
  \begingroup
    \settowidth{\@tempdima}{#1}%
    \ifdim\@tempdima>\maxallsectionnumberwidth
      \global\maxallsectionnumberwidth\@tempdima
    \fi
  \endgroup  
}
\BeforeClosingMainAux{%
  \if@filesw
    \ifdim\maxallsectionnumberwidth>\allsectionnumberwidth
      \typeout{Rerun to get section number width right!}%
      \immediate\write\@auxout{\unexpanded{%
          \providecommand*\setallsectionnumberwidth[1]{}^^J%
        }%
        \string\setallsectionnumberwidth{\the\maxallsectionnumberwidth}%
      }%
    \fi
  \fi
}
\newcommand*{\setallsectionnumberwidth}[1]{%
  \setlength{\allsectionnumberwidth}{#1}%
  \global\allsectionnumberwidth\allsectionnumberwidth
}
\makeatother

\setcounter{secnumdepth}{\subparagraphnumdepth}% To show it for all levels

\begin{document}
\chapter{Chapter Heading}
\section{Section Heading}
\subsection{Subsection Heading}
\subsubsection{Subsubsection Heading}
\paragraph{Paragraph Heading}
\subparagraph{Subparagraph Heading}
% Compare after adding
%\setcounter{section}{99}\setcounter{subparagraph}{999}\subparagraph{More}
\end{document}

Note: You need at least two LaTeX runs to get the number widths correct, e.g., after activating the commented line before the \end{document}.

See https://tex.stackexchange.com/a/357254/9057 if you want something like this on a per page basis instead of a per document basis.

| improve this answer | |
3

You could use something like

\newdimen\sectionnumberwdmax
\setlength\sectionnumberwdmax{1.25cm}% <- space needed for the section numbers

\renewcommand*{\chapterformat}{%
  \mbox{\chapappifchapterprefix{\nobreakspace}%
    \IfUsePrefixLine
      {\thechapter\autodot}
      {\makebox[\sectionnumberwdmax][l]{\thechapter\autodot\hfil}}%
  }%
}
\renewcommand*\sectionformat{\makebox[\sectionnumberwdmax][l]{\thesection\autodot\hfil}}

Example:

enter image description here

Code:

\documentclass[12pt, numbers=noenddot,parskip,headings=small,headsepline,listof=nochaptergap, listof=totoc,index=totoc]{scrreprt}
\usepackage[a4paper, includehead, left=3.5cm, right=1.7cm, top=2.5cm, bottom=2.0cm]{geometry}
\RedeclareSectionCommand[
  beforeskip=-1sp,
  afterskip=.25\baselineskip
]{chapter}
\RedeclareSectionCommand[
  beforeskip=-\baselineskip,
  afterskip=.5\baselineskip
]{section}
\RedeclareSectionCommand[
  beforeskip=-.75\baselineskip,
  afterskip=.5\baselineskip
]{subsection}
\RedeclareSectionCommand[
  beforeskip=-.5\baselineskip,
  afterskip=.25\baselineskip
]{subsubsection}
\RedeclareSectionCommands[
  beforeskip=.5\baselineskip,
  afterskip=-1em
]{paragraph,subparagraph}

\newdimen\sectionnumberwdmax
\setlength\sectionnumberwdmax{1.25cm}% <- space needed for the section numbers

\renewcommand*{\chapterformat}{%
  \mbox{\chapappifchapterprefix{\nobreakspace}%
    \IfUsePrefixLine
      {\thechapter\autodot}
      {\makebox[\sectionnumberwdmax][l]{\thechapter\autodot\hfil}}%
  }%
}
\renewcommand*\sectionformat{\makebox[\sectionnumberwdmax][l]{\thesection\autodot\hfil}}

\begin{document}
\chapter{Einleitung}
\section{Zielstellung}
\setcounter{section}{9}
\section{Abschnitt mit zweistelliger Nummer}
\end{document}
| improve this answer | |
  • For some reason this interferes with my header and places the heading too close to the headsepline if I use \usepackage[automark ]{scrlayer-scrpage} \automark{chapter} \clearpairofpagestyles \ihead{\headmark} \ohead{\pagemark} \renewcommand*{\chapterpagestyle}{headings} \renewcommand*{\chapterheadstartvskip}{\vspace*{-\topskip}} – Redfox87678 Jul 24 '17 at 12:55
  • 1
    Remove \renewcommand*{\chapterheadstartvskip}{\vspace*{-\topskip}} from your code. It shifts the chapter heading upwards over the border of the text area. The skip before the chapter heading is set by \RedeclareSectionCommand[beforeskip=-1sp,...]{chapter}. For more information see the documentation. – esdd Jul 24 '17 at 14:24

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.