
В классе scrreprt с помощью пакета tocstyle я хотел бы, чтобы слово "Глава 1" было жирным в TOC, но не название главы (см. изображение). Как этого добиться? По умолчанию все жирное. Использование \addtokomafont{chapterentry}{\mdseries}
изменяет шрифт всей строки записи TOC.
МВЭ:
\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}
решение1
Обратите внимание, что пакет tocstyle
больше не разрабатывается. Поэтому вы получите предупреждения.
Я бы предложил использовать команды, опции и т. д. пакета tocbasic
. Этот пакет также является частью пакета KOMA-Script, и класс KOMA-Script загружается tocbasic
автоматически.
Предложение без 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}
Запустите три раза, чтобы получить:
Если номер страницы главы также должен быть выделен жирным шрифтом, вы можете добавить
pagenumberformat=\usekomafont{chapterentry}\textbf
к вариантам \DeclareTOCStyleEntry
для главы.
Пример:
\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}
Запустите три раза, чтобы получить:
решение2
Вот способ добавления внутрь \textnormal
второго аргумента вашей определенной команды:
\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}