如何在 KOMA-script 中進行文件範圍的標題大小寫?

如何在 KOMA-script 中進行文件範圍的標題大小寫?

我想在 KOMA-script-typeset 標題頁和章節標題中使用標題大小寫。

當然,我可以做

\documentclass[version=last]{scrreprt} % it's 3.32
\usepackage{titlecaps}

\title{\titlecap{The Beginning of the document}}

\begin{document}
    \maketitle
    \tableofcontents
    \section{\titlecap{My title with caps}}
\end{document}          

不過,我想要一些慣用的東西,比如,

\setkomafont{disposition}{\rmfamily\MakeTitleCase}

如何自動化標題大小寫?

答案1

你可以修補\chapterlinesformat,,,,也許:\chapterlineswithprefixformat\sectionlinesformat\sectioncatchphraseformat\minisec

\usepackage{titlecaps}
\usepackage{xpatch}

\newcommand*\MakeTitleCase[1]{\titlecap{#1}}

\xpatchcmd\chapterlinesformat{#3}{\MakeTitleCase{#3}}{}{\clfpatchfailed}
\xpatchcmd\chapterlineswithprefixformat{#3}{\MakeTitleCase{#3}}{}{\clwpfpatchfailed}
\xpatchcmd\sectionlinesformat{#4}{\MakeTitleCase{#4}}{}{\slfpatchfailed}
\xpatchcmd\sectioncatchphraseformat{#4}{\MakeTitleCase{#4}}{}{\scpfpatchfailed}
\xpatchcmd\minisec{#1}{\MakeTitleCase{#1}}{}{\mspatchfailed}

對於標題,您可以使用

\newcommand*\originaltitle{}
\let\originaltitle\title
\renewcommand\title[1]{\originaltitle{\MakeTitleCase{#1}}}

\newcommand*\originaladdchaptertocentry{}
\let\originaladdchaptertocentry\addchaptertocentry
\renewcommand*\addchaptertocentry[2]{\originaladdchaptertocentry{#1}{\MakeTitleCase{#2}}}

只有章節條目才會\MakeTitleCase在目錄中使用。

如果目錄中的所有條目都應使用\MakeTitleCase

\newcommand*\originaladdtocentrydefault{}
\let\originaladdtocentrydefault\addtocentrydefault
\renewcommand*\addtocentrydefault[3]{\originaladdtocentrydefault{#1}{#2}{\MakeTitleCase{#3}}}

例子:

\documentclass[version=last]{scrreprt} % it's 3.32
\usepackage{titlecaps}
\usepackage{xpatch}

\newcommand*\MakeTitleCase[1]{\titlecap{#1}}

\xpatchcmd\chapterlinesformat{#3}{\MakeTitleCase{#3}}{}{\clfpatchfailed}
\xpatchcmd\chapterlineswithprefixformat{#3}{\MakeTitleCase{#3}}{}{\clwpfpatchfailed}
\xpatchcmd\sectionlinesformat{#4}{\MakeTitleCase{#4}}{}{\slfpatchfailed}
\xpatchcmd\sectioncatchphraseformat{#4}{\MakeTitleCase{#4}}{}{\scpfpatchfailed}
\xpatchcmd\minisec{#1}{\MakeTitleCase{#1}}{}{\mspatchfailed}

\newcommand*\originaltitle{}
\let\originaltitle\title
\renewcommand\title[1]{\originaltitle{\MakeTitleCase{#1}}}


\newcommand*\originaladdtocentrydefault{}
\let\originaladdtocentrydefault\addtocentrydefault
\renewcommand*\addtocentrydefault[3]{\originaladdtocentrydefault{#1}{#2}{\MakeTitleCase{#3}}}

\title{The Beginning of the document}
\author{Author}
\begin{document}
\maketitle
\tableofcontents
\chapter{A chapter with caps}
\section{A section with caps}
\minisec{A minisec with caps}
\paragraph{A paragraph with caps}
Example text ...
\end{document}

在此輸入影像描述

相關內容