
scrreprt クラスで、パッケージ tocstyle を使用して、TOC 内の「Chapter 1」という単語を太字にしたいのですが、章のタイトルは太字にしたくないです (画像を参照)。どうすればこれを実現できますか? デフォルトでは、すべてが太字です。 を使用すると、\addtokomafont{chapterentry}{\mdseries}
TOC エントリ行全体のフォントが変更されます。
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}
答え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}
3 回実行すると次のようになります:
章のエントリのページ番号も太字にしたい場合は、
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}
3 回実行すると次のようになります:
答え2
\textnormal
定義したコマンドの 2 番目の引数内に追加する方法を次に示します。
\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}