2

I would like to remove the linked page numbers of the LoF and LoT inside the TOC. The page numbers should start appearing with the first chapter.

\documentclass[listof = totoc]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage{graphicx, duckuments}
\usepackage{scrlayer-scrpage}
\usepackage{hyperref}

\begin{document}

    \hypersetup{pageanchor=false}
    \pagestyle{empty}
    \renewcommand*{\chapterpagestyle}{empty}

    \tableofcontents % no page number for lof, lot wanted inside toc
    \listoffigures

    \cleardoubleoddpage
    \pagestyle{scrheadings}
    \renewcommand*{\chapterpagestyle}{plain}
    \hypersetup{pageanchor=true}
    \pagenumbering{arabic}

    \duckument

    \begin{figure}
        \includegraphics{example-image-duck}
        \caption{I'm a random duck}
    \end{figure}
\end{document}

I don't mean the actual page number at the bottom. The number I mean is printed on the right handside at the \tableofcontents. enter image description here

faltfe
  • 519

1 Answers1

4

Here are two suggestions.

You could use a switch in the code for tocpagenumberformat

\documentclass[listof = totoc]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{duckuments}% only for dummy text
\usepackage{scrlayer-scrpage}
\usepackage{hyperref}
\hypersetup{hypertexnames=false}

\RedeclareSectionCommand[
  tocpagenumberformat=\tocchapterpagenumberformat
]{chapter}

\newif\ifgobblechaptertocpagenumber
\newcommand*\tocchapterpagenumberformat[1]
  {{\ifgobblechaptertocpagenumber\else{\usekomafont{chapterentrypagenumber}#1}\fi}}

\begin{document}
\hypersetup{pageanchor=false}
\renewcommand*\chapterpagestyle{empty}
\pagestyle{empty}
\addtocontents{toc}{\protect\gobblechaptertocpagenumbertrue}

\tableofcontents % no page number for lof, lot wanted inside toc
\listoffigures

\cleardoubleoddpage
\hypersetup{pageanchor=true}
\pagenumbering{arabic}
\renewcommand\chapterpagestyle{plain}
\pagestyle{scrheadings}
\addtocontents{toc}{\protect\gobblechaptertocpagenumberfalse}
\duckument
\begin{figure}
    \includegraphics{example-image-duck}
    \caption{I'm a random duck}
\end{figure}
\end{document}

enter image description here

Or you could define a new entry listchapter and patch \addchaptertocentry for the lists to use listchapter instead chapter:

\documentclass[listof= totoc]{scrreprt}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{duckuments}% only for dummy text
\usepackage{scrlayer-scrpage}
\usepackage{hyperref}

\DeclareTOCStyleEntry[
  level=\chaptertocdepth,
  indent=0pt,
  numwidth=1.5em,
  pagenumberformat=\gobblepagenumber
]{chapter}{listchapter}
\newcommand\gobblepagenumber[1]{}
\usepackage{xpatch}
\BeforeTOCHead{%
  \xpatchcmd{\addchaptertocentry}{chapter}{listchapter}{}{\addchapPatchFailed}%
}

\begin{document}
\hypersetup{pageanchor=false}
\pagestyle{empty}
\renewcommand*{\chapterpagestyle}{empty}

\tableofcontents % no page number for lof, lot wanted inside toc
\listoffigures

\cleardoubleoddpage
\hypersetup{pageanchor=true}
\pagenumbering{arabic}
\pagestyle{scrheadings}
\renewcommand*{\chapterpagestyle}{plain}

\duckument
\begin{figure}
    \includegraphics{example-image-duck}
    \caption{I'm a random duck}
\end{figure}
\end{document}

The result is the same as above.

esdd
  • 85,675
  • Thanks for this great answer. It is working as expected. I'll use the second approach because it seems somehow more clear to me. – faltfe Jul 11 '18 at 13:26