Using a KOMA-script class, I would like to customize the presentation of the pagenumbers in the table of contents.
My pagenumbers are reset every section and are represented like 2-3
which means page 3
of section 2
. This is not achieved by changing the \thepage
command but by simply writing in the footer {\thesection-\thepage}
.
When creating the toc, obviously only \thepage
-number is shown. What I would like to achieve is a number format like this:
1 Sectiontitle
1.1 Subsectiontitle .............. 1-1
1.2 Other title .................. 1-2
2 Next Section
2.1 This Section ................. 2-1
I would like to keep the definition of \thepage
as it's default, since I might be needing the number for other applications.
I already found various posts (here or here or here) regarding the formatting of the toc, but I didn't find anything regarding the format of the page numbers.
Edit 1:
I believe, that using the pagenumberbox
command from the tocstyle
-package should do the job of putting something in front of the pagenumber. However, I'm still clueless on how achieving the right section number to put into the pagenumberbox
Edit 2:
MWE:
\documentclass[english,footsepline,listof=totoc]{scrartcl}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{float}
\makeatletter
\usepackage{geometry}
\geometry{a4paper,verbose=true,nomarginpar,tmargin=4cm,bmargin=2.2cm,footskip=1.1cm,lmargin=3cm,rmargin=2.5cm,headheight=3cm}
\setlength{\footheight}{1cm}
%% Begin of way to indent all body but no headings
\newcommand\LeftMargin{.5cm}
\renewcommand*\sectionlinesformat[4]{ \ifstr{#3}{}{}{\hspace*{-\LeftMargin}}#3#4}
\usepackage[ headwidth=\the\textwidth+\LeftMargin:-\LeftMargin:\LeftMargin,footwidth=\the\textwidth+\LeftMargin:-\LeftMargin:\LeftMargin]{scrlayer-scrpage}
%% Define how deep the numeration in the document should be.
\setcounter{secnumdepth}{5}
%% Define how deep the numeration in the table of contents should be.
\setcounter{tocdepth}{3}
\pagestyle{scrheadings} %same as above
%% Define customized pagenumbering
\let\stdsection\section
\renewcommand\section{%
\clearpage%
\setcounter{page}{1}%
\stdsection%
}
\clearscrheadfoot
\ofoot{\raisebox{-2mm}{\thesection-\thepage}}
\cfoot{\raisebox{-2mm}{Footer}}
\setkomafont{pageheadfoot}{\normalfont}
\usepackage[nohyperlinks]{acronym}
\begin{document}
\tableofcontents{}
\section{First}
\newpage
\section{Second}
Content
\end{document}
Edit 3:
Based on the below-stated answer, I was able to achieve the page-numbering I wanted. Only problem is, that the page numbers in the toc seem to be somehow aligned (see image below).
This looks obviously strange, is there some way of aligning the page-numbers right rather than left?
Best Answer
Disclaimer: I do not recommend such a strange page numbering, certainly not without changing
\thepage
.But it is possible using the current prerelease of KOMA-Script 3.20.
Update regarding the alignment of the page numbers in TOC
A page number of an entry is printed right aligned in a box of width
\@pnumwidth
. So maybe you want to enlarge\@pnumwidth
using for exampleOr you can use a
\mbox
astocpagenumberbox
.Code: