1

When I add the table of contents and have roman page numbering in the beginning, the roman page numbers are not right aligned.

MWE:

\documentclass[twoside, openright]{scrreprt}
\usepackage[ngerman]{babel}
\usepackage{lipsum}
\usepackage{hyperref}

\newcommand{\uchapter}[1]{% add unnumbered chapter
    \phantomsection
    \chapter*{#1}
    \addcontentsline{toc}{chapter}{#1}}

\begin{document}
    
\pagenumbering{Roman}
\setcounter{page}{3}

\uchapter{Abstract}
\lipsum[1-2]
\tableofcontents
\uchapter{Abbildungsverzeichnis}
\uchapter{Tabellenverzeichnis}
\uchapter{Formelverzeichnis}
\uchapter{Symbolverzeichnis}
\uchapter{Abkürzungsverzeichnis}
\uchapter{Sperrvermerk}



\end{document}

Apparent solutions to this problem that I have found online either used packages not compatible to KOMA (tocloft) or outdated packages (tocstyle). Is there an option or argument perhaps that I am missing to solve this?

1
  • 1
    Your roman numbers are too wide for the available space (macro \@pnumwidth) and are pushing into the margin. The easy solution is to use \scrbook and \frontmatter. Jul 4, 2021 at 16:45

1 Answer 1

2

There are different possiblilties to enlarge the available space for page numbers.

If there are only chapter entries with Roman page numbers, you can enlarge the space only for chapters using

\DeclareTOCStyleEntry[
  pagenumberwidth=2.55em,% default is \@pnumwidth (default is 1.55em)
  rightindent=3.55em% default is \@tocrmarg (default is 2.55em)
]{tocline}{chapter}

Example:

\documentclass[twoside, open=right]{scrreprt}
\usepackage[ngerman]{babel}
\usepackage{blindtext}% only for dummy text
\usepackage{hyperref}

\DeclareTOCStyleEntry[
  %pagenumberbox=\mbox
  pagenumberwidth=2.55em,
  rightindent=3.55em
]{tocline}{chapter}

\begin{document}
\cleardoubleoddpage
\pagenumbering{Roman}
\setcounter{page}{3}

\addchap{Abstract}
\Blindtext[2]
\tableofcontents
\addchap{Abbildungsverzeichnis}
\addchap{Tabellenverzeichnis}
\addchap{Formelverzeichnis}
\addchap{Symbolverzeichnis}
\addchap{Abkürzungsverzeichnis}
\addchap{Sperrvermerk}

\cleardoubleoddpage
\pagenumbering{arabic}
\Blinddocument
\Blinddocument
\end{document}

enter image description here

You can enlarge the space for all levels:

\makeatletter
\renewcommand{\@pnumwidth}{2.55em}% default is 1.55em
\renewcommand{\@tocrmarg}{3.55em}% default is 2.55em
\makeatother

Example:

\documentclass[twoside, open=right]{scrreprt}
\usepackage[ngerman]{babel}
\usepackage{blindtext}% only for dummy text
\usepackage{hyperref}

\makeatletter
\renewcommand{\@pnumwidth}{2.55em}% default is 1.55em
\renewcommand{\@tocrmarg}{3.55em}% default is 2.55em
\makeatother

\begin{document}
\cleardoubleoddpage
\pagenumbering{Roman}
\setcounter{page}{3}

\addchap{Abstract}
\Blindtext[2]
\tableofcontents
\addchap{Abbildungsverzeichnis}
\addchap{Tabellenverzeichnis}
\addchap{Formelverzeichnis}
\addchap{Symbolverzeichnis}
\addchap{Abkürzungsverzeichnis}
\addchap{Sperrvermerk}

\cleardoubleoddpage
\pagenumbering{arabic}
\Blinddocument
\Blinddocument
\end{document}

enter image description here

Of course you can also change pagenumberwidth and rightindent locally in TOC:

\documentclass[twoside, open=right]{scrreprt}
\usepackage[ngerman]{babel}
\usepackage{blindtext}% only for dummy text
\usepackage{hyperref}

\newcommand*\settocpagenumberwidth[2]{%
  \DeclareTOCStyleEntries[pagenumberwidth=#1,rightindent=#2]{tocline}{chapter,section}%
}

\makeatletter
\newcommand*\resettocpagenumberwidth{%
  \DeclareTOCStyleEntries[pagenumberwidth=\@pnumwidth,rightindent=\@tocrmarg]{tocline}{chapter,section}%
}
\makeatother

\begin{document}
\cleardoubleoddpage
\pagenumbering{Roman}
\setcounter{page}{3}
\addtocontents{toc}{\settocpagenumberwidth{2.55em}{3.55em}}

\addchap{Abstract}
\Blindtext[2]
\tableofcontents
\addchap{Abbildungsverzeichnis}
\addchap{Tabellenverzeichnis}
\addchap{Formelverzeichnis}
\addchap{Symbolverzeichnis}
\addsec{Foo}
\addsec{Bar}
\addchap{Abkürzungsverzeichnis}
\addchap{Sperrvermerk}
\addsec{Abschnitt 1}
\addsec{Abschnitt 2}

\cleardoubleoddpage
\pagenumbering{arabic}
\addtocontents{toc}{\resettocpagenumberwidth}
\Blinddocument
\Blinddocument
\end{document}

enter image description here

If there is no dotted line for chapter entries, you could change the box for the page numbers to \mbox:

\DeclareTOCStyleEntry[pagenumberbox=\mbox]{tocline}{chapter}

Additional remark: If you need unnumbered chapters with TOC entries, use KOMA-Script command \addchap. For unnumbered chapters without TOC entry use \addchap*. You can also switch to scrbook. This class provides \frontmatter and \mainmatter. Then you can use \chapter in the front matter for unnumbered chapters with TOC entries.

2
  • You could use \addtocontents to change \@pnumwidth in the middle of the TOC. Jul 5, 2021 at 1:56
  • @JohnKormylo I have added an example with a local change of pagenumberwidth and rightindent. But of course there are other ways, too.
    – esdd
    Jul 5, 2021 at 8:18

You must log in to answer this question.

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