在 scrartcl/KOMA 中更改摘要标题字体

在 scrartcl/KOMA 中更改摘要标题字体

abstract我想更改中的标题字体scrartcl

latexdef告诉我,在我的情况下 (no titlepage, no twocolumn),\sectfont用法是:

> latexdef -c scrartcl -s abstract
...
\begin{center}
  {\normalfont\sectfont\nobreak\abstractname
    \vspace{-.5em}\vspace{\z@}}%
\end{center}
...

因此我尝试使用常规方法进行设置\setkomafont

\documentclass[abstract = true]{scrartcl}

\setkomafont{section}{\centering\normalfont\itshape}

\begin{document}

\begin{abstract}% this heading should be in the same style as the section title below
  Text
\end{abstract}

\section{Section Title}% for comparison

\end{document}

然而,摘要标题的字体根本没有改变。

我不确定这是预期的行为还是错误,以及是否需要使用其他命令来设置抽象标题字体,特别是因为:

> latexdef -c scrartcl -s abstract
...
\if@twocolumn\if@abstrt
    \addsec*{\abstractname}
  \fi
...

这次(\documentclass[abstract = true, twocolumn]{scrartcl}),摘要标题字体确实改变了。

不可否认,可以通过全局更改字体,\setkomafont{disposition}然后在abstract调用后重置它,但是,对我来说这似乎是一个非常不优雅的解决方案。

我还有哪些更好的选择?

答案1

选项abstract=true启用摘要的自动标题。因此,如果您想使用自己的摘要标题,请删除选项abstract=true。然后您可以使用例如\addsec*{\abstractname}

\documentclass[
   %abstract=true% <- remove this option, if there should be no automatic heading in the abstract
]{scrartcl}
\usepackage{blindtext}% only for dummy text in the example

\setkomafont{section}{\normalfont\itshape}
\renewcommand{\raggedsection}{\centering}% \centering is no font command!

\begin{document}
\addsec*{\abstractname}
\begin{abstract}
  \blindtext
\end{abstract}

\section{Section Title}% for comparison
\Blindtext
\end{document}

在此处输入图片描述

题外话:\centering不是字体命令。因此不建议将其用于\centering字体元素。

答案2

从文件中看到的内容来看scrartcl.clsabstract环境使用\sectfont命令来格式化一列文档中的“摘要”标题:

    \begin{center}
      {\normalfont\sectfont\nobreak\abstractname
        \vspace{-.5em}\vspace{\z@}}%
    \end{center}

我们可以重新定义此命令,但这也会影响使用它的其他命令(例如\titlefont)。出于这些原因,我认为最简单的方法是:

\usepackage{etoolbox}
\AtBeginEnvironment{abstract}{\def\sectfont{\normalsize\itshape}}

第二个不太优雅的解决方案可能是这样的:

\renewcommand*{\abstractname}{\normalsize\rmfamily\itshape\mdseries Abstract}

以下是一个 mwe:

\documentclass[abstract = true]{scrartcl}
  \setkomafont{section}{\centering\normalfont\itshape}
\usepackage{etoolbox}
  \AtBeginEnvironment{abstract}{\def\sectfont{\normalsize\itshape}}
\begin{document}
 \begin{abstract}% this heading should be in the same style as the section title below
  Text of the abstract text of the abstract of the abstract of the abstract of the abstract of the abstract of the abstract of the abstract of the abstract of the abstract of the abstract of the abstract of the abstract of the abstract of the abstract 
\end{abstract}
 \section{Section Title}% for comparison
\end{document}

在此处输入图片描述

相关内容