
在 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
不再開發。因此您會收到警告。
我建議使用 package 的命令、選項等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
到for 章節的選項。
例子:
\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}