# Page numbering of custom TOC (DeclareNewTOC) are overlapping textwidth

I declared a custom TOC for some floats with the following command:

\documentclass{scrartcl}
\DeclareNewTOC[%
type=questiona,%
name=table,%
float,%
listname={Question Overview},%
]{qua}

\usepackage{blindtext}

\begin{document}
\blindtext
\listoftoc{qua}
\pagenumbering{roman}
\setcounter{page}{223}
\captionof{questiona}{First Caption with very long text that keeps moving and moving and there is still no end to see}
\setcounter{questiona}{49}
\captionof{questiona}{Foo}
\setcounter{questiona}{999}
\captionof{questiona}{Bar}
\end{document}


I have a lot of entries (>50) in the TOC. The entry page numbering is roman, so the page number width can be very wide. I run into the problem that the TOC page numbering now overlaps the text width and I cannot find any switch to change that appropriately.

Is there a way to calculate the right number width automatically or manually tweak the value for my purpose?

Update (because question has changed)

You could redefine and \@pnumwidth and \@tocrmargin. Example:

\makeatletter
\renewcommand*\@pnumwidth{3em}% default: 1.55em
\renewcommand*\@tocrmarg{4em}% default: 2.55em
\makeatother


To restrict this change to the "Question Overview" use

\makeatletter
\renewcommand*\@pnumwidth{3em}% default: 1.55em
\renewcommand*\@tocrmarg{4em}% default: 2.55em
}
\makeatother


Example:

\documentclass{scrartcl}
\DeclareNewTOC[%
type=questiona,%
name=table,%
float,%
listname={Question Overview},%
tocentrydynnumwidth%
]{qua}

\makeatletter
\renewcommand*\@pnumwidth{3em}% default: 1.55em
\renewcommand*\@tocrmarg{4em}% default: 2.55em
}
\makeatother

\usepackage{blindtext}% only for dummy text
\begin{document}
\tableofcontents
\section{A section}
\subsection{A subsection}
\blindtext
\listoftoc{qua}
\cleardoublepage
\pagenumbering{roman}
\captionof{questiona}{A caption}
\cleardoublepage
\setcounter{page}{223}
\captionof{questiona}{First Caption with very long text that keeps moving and moving and there is still no end to see}
\setcounter{questiona}{49}
\captionof{questiona}{Foo}
\setcounter{questiona}{999}
\captionof{questiona}{Bar}
\end{document}


Result:

Additional remark: Prerelease of KOMA-Script version 3.27 provides the new options tocentrypagenumberwidth and tocentryrightmargin for new declared TOCs:

\documentclass{scrartcl}
\DeclareNewTOC[%
type=questiona,%
name=table,%
float,%
listname={Question Overview},%
tocentrydynnumwidth,
tocentrypagenumberbox=\mbox
]{qua}

\usepackage{blindtext}% only for dummy text
\begin{document}
\tableofcontents
\section{A section}
\subsection{A subsection}
\blindtext
\listoftoc{qua}
\cleardoublepage
\pagenumbering{roman}
\captionof{questiona}{A caption}
\cleardoublepage
\setcounter{page}{223}
\captionof{questiona}{First Caption with very long text that keeps moving and moving and there is still no end to see}
\setcounter{questiona}{49}
\captionof{questiona}{Foo}
\setcounter{questiona}{999}
\captionof{questiona}{Bar}
\end{document}


The result is the same as above.

You can use option tocentrynumwidth=<length> to adjust the space for the numbers. But with option tocentrydynnumwidth the needed width is calculated automatically.

Example:

\documentclass{scrartcl}
\DeclareNewTOC[%
type=questiona,%
name=table,%
float,%
listname={Question Overview},%
]{qua}
\begin{document}
\listoftoc{qua}
\captionof{questiona}{First Caption}
\setcounter{questiona}{49}
\captionof{questiona}{Foo}
\setcounter{questiona}{999}
\captionof{questiona}{Bar}
\end{document}


Additional remark: The calculated value is only used, if it is larger than the value of tocentrynumwidth (default 2.3em). So, if option tocentrydynnumwidth is set, the value of tocentrynumwidth is the minimal width for the numbers.

% example needs prerelease of KOMA-Script 3.27 (see KOMA-Script website)
\documentclass{scrartcl}
\DeclareNewTOC[%
type=questiona,%
name=table,%
float,%
listname={Question Overview},%
tocentrydynnumwidth,
tocentrypagenumberwidth=10em,% default 1.55em
tocentryrightindent=4em,% default 2.55em
]{qua}

\usepackage{blindtext}% only for dummy text
\begin{document}
\tableofcontents
\section{A section}
\subsection{A subsection}
\blindtext
\listoftoc{qua}
\cleardoublepage
\pagenumbering{roman}
\captionof{questiona}{A caption}
\cleardoublepage
\setcounter{page}{223}
\captionof{questiona}{First Caption with very long text that keeps moving and moving and there is still no end to see}
\setcounter{questiona}{49}
\captionof{questiona}{Foo}
\setcounter{questiona}{999}
\captionof{questiona}{Bar}
\end{document}

• you are totally right. I asked the wrong question. I was looking for parameter for the page numbering. This column is not inside the textwidth. – aronadaal Sep 15 '19 at 9:07
• @aronadaal See my updated answer. But it would have been better to ask a new question than to change the original one. – esdd Sep 15 '19 at 17:22