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.
\documentclass
followed by only the preamble code, that is needed to reproduce the problem, and followed by a document body from\begin{document}
to\end{document}
? This makes is easier and faster to help you. So please help us to help you. – Schweinebacke Jul 24 '17 at 7:01\chapterformat
and\sectionformat
in the KOMA-Script manual (or same in German). You will find, that there are similar commands for all other section levels. – Schweinebacke Jul 24 '17 at 8:31