tocstyle:在目录中将单词“第 1 章”加粗,但不将章节标题加粗

tocstyle:在目录中将单词“第 1 章”加粗,但不将章节标题加粗

在 scrreprt 类中,使用 tocstyle 包,我希望目录中的单词“第 1 章”为粗体,但章节标题不为粗体(见图)。我该如何实现?默认情况下,所有内容都是粗体。使用\addtokomafont{chapterentry}{\mdseries}可更改整个目录条目行的字体。

在此处输入图片描述

梅威瑟:

\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}

在此处输入图片描述

相关内容