2

In the scrreprt class, using the package tocstyle, I would like the word "Chapter 1" to be bold in the TOC, but not the title of the chapter (see image). How do I achieve this? As per default, everything is bold. Using \addtokomafont{chapterentry}{\mdseries} changes the font of the entire TOC entry line.

enter image description here

MWE:

\documentclass[twoside, openright, BCOR=1cm, headsepline,chapterprefix=true]{scrreprt}

%%---header/footer
\usepackage[manualmark]{scrlayer-scrpage}

\automark{chapter}
%%--"Chapter #" in lehead, chapter name in rohead
\renewcommand*\chaptermark[1]{%
    \markboth{\ifnumbered{chapter}{\chaptermarkformat}{}}{#1}%
}

\AfterTOCHead[toc]{\markboth{}{\contentsname}}


\usepackage{lipsum}

%%---add "Chapter #" in TOC before chapter title, only for numbered chapters
\let\oldaddchaptertocentry\addchaptertocentry
\renewcommand{\addchaptertocentry}[2]{%
    \ifstr{#1}{}{%
        \oldaddchaptertocentry{#1}{#2}}{%
        \oldaddchaptertocentry{\chapapp{} #1}{#2}%
}}


\usepackage[toctextentriesindented]{tocstyle}
\usetocstyle{KOMAlike}
\settocstylefeature{spaceafternumber}{16pt}

\setcounter{secnumdepth}{0}
\setcounter{tocdepth}{0}

\begin{document}

\tableofcontents

\chapter{An interesting title}
\thispagestyle{empty}

\newpage

\section{A slightly less interesting title}
\lipsum[1-5]

\addchap{Unnumbered chapter}
\thispagestyle{empty}

\newpage

\section{Section title}
\lipsum[6-15]

\end{document}

2 Answers 2

1

Note that package tocstyle is not developed anymore. Therefore you will get warnings.

I would suggest to use commands, options etc. of package tocbasic. This package is also part of the KOMA-Script bundle and the KOMA-Script class loads tocbasic automatically.

Suggestion without tocstyle:

\documentclass[twoside, openright, BCOR=1cm, headsepline,chapterprefix=true,
  toc=indentunnumbered% <- added
]{scrreprt}
\usepackage{lipsum}% only for dummy text

%%---header/footer
\usepackage[manualmark]{scrlayer-scrpage}

\automark{chapter}
%%--"Chapter #" in lehead, chapter name in rohead
\renewcommand*\chaptermark[1]{%
    \markboth{\ifnumbered{chapter}{\chaptermarkformat}{}}{#1}%
}

\AfterTOCHead[toc]{\markboth{}{\contentsname}}

\addtokomafont{chapterentry}{\mdseries}
\DeclareTOCStyleEntry[
  entrynumberformat=\textbf,
  numsep=16pt,
  dynnumwidth
]{chapter}{chapter}

%%---add "Chapter #" in TOC before chapter title, only for numbered chapters
\let\oldaddchaptertocentry\addchaptertocentry
\renewcommand{\addchaptertocentry}[2]{%
    \ifstr{#1}{}{%
        \oldaddchaptertocentry{#1}{#2}}{%
        \oldaddchaptertocentry{\chapapp{} #1}{#2}%
}}

\setcounter{secnumdepth}{\chapternumdepth}
\setcounter{tocdepth}{\chaptertocdepth}

\renewcommand\chapterpagestyle{empty}% if all chapter pages should use page style empty
\begin{document}

\tableofcontents
\chapter{An interesting title}
\newpage
\section{A slightly less interesting title}
\lipsum[1-5]

\addchap{Unnumbered chapter}
\newpage
\section{Section title}
\lipsum[6-15]
\end{document}

Run three times to get:

enter image description here


If the page number of the chapter entry should be bold too, you can add

pagenumberformat=\usekomafont{chapterentry}\textbf

to the options of \DeclareTOCStyleEntry for chapter.

Example:

\documentclass[twoside, openright, BCOR=1cm, headsepline,chapterprefix=true,
  toc=indentunnumbered% <- added
]{scrreprt}
\usepackage{lipsum}% only for dummy text

%%---header/footer
\usepackage[manualmark]{scrlayer-scrpage}

\automark{chapter}
%%--"Chapter #" in lehead, chapter name in rohead
\renewcommand*\chaptermark[1]{%
    \markboth{\ifnumbered{chapter}{\chaptermarkformat}{}}{#1}%
}

\AfterTOCHead[toc]{\markboth{}{\contentsname}}

\addtokomafont{chapterentry}{\mdseries}
\DeclareTOCStyleEntry[
  entrynumberformat=\textbf,
  pagenumberformat=\usekomafont{chapterentry}\textbf,
  dynnumwidth
]{chapter}{chapter}

%%---add "Chapter #" in TOC before chapter title, only for numbered chapters
\let\oldaddchaptertocentry\addchaptertocentry
\renewcommand{\addchaptertocentry}[2]{%
    \ifstr{#1}{}{%
        \oldaddchaptertocentry{#1}{#2}}{%
        \oldaddchaptertocentry{\chapapp{} #1}{#2}%
}}

\setcounter{secnumdepth}{\chapternumdepth}
\setcounter{tocdepth}{\chaptertocdepth}

\renewcommand\chapterpagestyle{empty}% if all chapter pages should use page style empty
\begin{document}

\tableofcontents
\chapter{An interesting title}
\newpage
\section{A slightly less interesting title}
\lipsum[1-5]

\addchap{Unnumbered chapter}
\newpage
\section{Section title}
\lipsum[6-15]
\end{document}

Run three times to get:

enter image description here

1

Here is a way by adding inside \textnormal the second argument of your defined command:

\documentclass[twoside, openright, BCOR=1cm, headsepline,chapterprefix=true]{scrreprt}

%%---header/footer
\usepackage[manualmark]{scrlayer-scrpage}

\automark{chapter}
%%--"Chapter #" in lehead, chapter name in rohead
\renewcommand*\chaptermark[1]{%
    \markboth{\ifnumbered{chapter}{\chaptermarkformat}{}}{#1}%
}

\AfterTOCHead[toc]{\markboth{}{\contentsname}}


\usepackage{lipsum}

%%---add "Chapter #" in TOC before chapter title, only for numbered chapters
\let\oldaddchaptertocentry\addchaptertocentry
\renewcommand{\addchaptertocentry}[2]{%
    \ifstr{#1}{}{%
        \oldaddchaptertocentry{#1}{\textnormal{#2}}}{%
        \oldaddchaptertocentry{\chapapp{} #1}{\textnormal{#2}}%
}}


\usepackage[toctextentriesindented]{tocstyle}
\usetocstyle{KOMAlike}
\settocstylefeature{spaceafternumber}{16pt}

\setcounter{secnumdepth}{0}
\setcounter{tocdepth}{0}

\begin{document}

\tableofcontents

\chapter{An interesting title}
\thispagestyle{empty}

\newpage

\section{A slightly less interesting title}
\lipsum[1-5]

\addchap{Unnumbered chapter}
\thispagestyle{empty}

\newpage

\section{Section title}
\lipsum[6-15]

\end{document}

enter image description here

You must log in to answer this question.

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