带有 KOMA 字体的大写章节

带有 KOMA 字体的大写章节

已经提到,在章节中获取大写字母可能比较棘手scrbook。但是,解决方案在 \@startsection 中使用 \MakeUppercase效劳于scrreprt

所使用的解决方案tudscr添加了自定义命令以使文本大写,但随后必须重新定义章节。

\makeatletter
    \newcommand*\mymakeuppercase[1]{%
        \ifdin{\begingroup\MakeTextUppercase{#1}\endgroup}{#1}%
    }
\makeatother

还有其他适用于所有 koma 脚本的替代方案吗?

梅威瑟:

\documentclass[chapterprefix=on]{scrbook}

% Fix \MakeUppercase
\usepackage{makerobust}
\makeatletter
\MakeRobustCommand\@hangfrom
\newcommand*{\ModMakeUppercase}{%
    \MakeRobustCommand\@svsec
    \MakeUppercase
}
\makeatother

\addtokomafont{part}{\MakeUppercase}
\addtokomafont{chapter}{\MakeUppercase} % <- doesn't work
\addtokomafont{section}{\ModMakeUppercase}
\addtokomafont{subsection}{\ModMakeUppercase}


\begin{document}
\tableofcontents
\end{document}

答案1

更新

自从KOMA-Script 版本 3.19推荐的方法是重新定义\sectionlinesformat\chapterlinesformat

\documentclass[chapterprefix]{scrbook}[2015/10/03]

\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \@hangfrom{\hskip #2#3}{\MakeUppercase{#4}}%
}
\renewcommand\chapterlinesformat[3]{%
  \@hangfrom{#2}{\MakeUppercase{#3}}%
}
\makeatother
\renewcommand\chapterlineswithprefixformat[3]{%
  \MakeUppercase{#2#3}%
}
\renewcommand{\sectioncatchphraseformat}[4]{%
  \hskip #2#3\MakeUppercase{#4}%
}

\usepackage{blindtext}
\begin{document}
\tableofcontents
\listoffigures
\chapter{Test}
\KOMAScriptVersion
\blinddocument
\end{document}

在此处输入图片描述


KOMA-Script 版本 3.16(和 3.15)中存在问题。解决方法:

\documentclass[chapterprefix=on]{scrbook}

% Fix \MakeUppercase
\usepackage{makerobust}
\makeatletter
\MakeRobustCommand\@hangfrom
\newcommand*{\ModMakeUppercase}{%
    \MakeRobustCommand\@svsec
    \MakeUppercase
}
\makeatother

\addtokomafont{part}{\MakeUppercase}
\addtokomafont{chapter}{\MakeUppercase}
\addtokomafont{section}{\ModMakeUppercase}
\addtokomafont{subsection}{\ModMakeUppercase}

% workaround for version 3.15 and 3.16
\deftocheading{toc}{\chapter*{#1}}% <- added
\deftocheading{lof}{\chapter*{#1}}% <- added
\deftocheading{lot}{\chapter*{#1}}% <- added

\usepackage{blindtext}
\begin{document}
\tableofcontents
\listoffigures
\chapter{Test}
\KOMAScriptVersion
\blinddocument
\end{document}

相关内容