![如何在 KOMA-script 中实现文档范围的标题大小写大写?](https://linux22.com/image/423431/%E5%A6%82%E4%BD%95%E5%9C%A8%20KOMA-script%20%E4%B8%AD%E5%AE%9E%E7%8E%B0%E6%96%87%E6%A1%A3%E8%8C%83%E5%9B%B4%E7%9A%84%E6%A0%87%E9%A2%98%E5%A4%A7%E5%B0%8F%E5%86%99%E5%A4%A7%E5%86%99%EF%BC%9F.png)
我想在 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}