如何调整 KOMA-Script 课程中章节标题前后的垂直间距以使其对称?

如何调整 KOMA-Script 课程中章节标题前后的垂直间距以使其对称?

下面是使用以下方法编译的 MWE LuaLaTeX

平均能量损失

% !TEX program = lualatex
\documentclass[12pt, DIV=12, numbers=noenddot]{scrartcl}

\usepackage{setspace}
\usepackage[english]{babel}
\usepackage{xpatch}
\usepackage{lipsum}
\usepackage{showframe}

    % Replace \autodot with "." for \section headings
\xpretocmd{\sectionformat}{\def\autodot{.}}{}{\cfPatchFailed} 
    % Section heading font settings
\addtokomafont{sectioning}{\rmfamily}
\setkomafont{section}{\Large}
\setkomafont{subsection}{\large}
\setkomafont{subsubsection}{\normalsize}

    % Spacing of section headings
\RedeclareSectionCommand[
    beforeskip=-0.25\baselineskip,
    afterskip=0.25\baselineskip
]{section}
\RedeclareSectionCommand[
    beforeskip=-0.25\baselineskip,
    afterskip=0.25\baselineskip
]{subsection}
\RedeclareSectionCommand[
    beforeskip=-0.25\baselineskip,
    afterskip=0.25\baselineskip
]{subsubsection}

\begin{document}
\onehalfspacing
\KOMAoptions{DIV=current}

\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\subsection{Subsection}
\section{Section}
\lipsum[1][1-5]
\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\subsection{Subsection}
\section{Section}
\end{document}

\section我希望s、\subsections 和s前后的垂直间距\subsubsection对称(因此我将beforeskip和设置afterskip为相等),但我不知道如何实现这一点,因为仔细检查后发现间距似乎不对称。(为了清楚起见,我在 Acrobat 中突出显示了文本。)

突出显示 MWE 1

突出显示 MWE 2

我的问题是

beforeskip为什么即使和afterskip相等,节标题前后的垂直间距也不对称?

如何调整 KOMA-Script 课程中章节标题前后的垂直间距以使其对称?

谢谢。

答案1

\baselineskip取决于字体大小。因此,如果您对节使用的字体比对小节使用的字体大,则节后的间距大于小节后的间距,并且小节紧跟在节后面,节与小节之间的间距是节后的(较大)间距,而不是小节前的间距。因此,如果您希望所有地方的间距都相同,则必须使用绝对值,例如 5pt:

% !TEX program = lualatex
\documentclass[12pt, DIV=12, numbers=noenddot]{scrartcl}

\usepackage{xcolor}
\usepackage{setspace}
\usepackage[english]{babel}
\usepackage{xpatch}
\usepackage{lipsum}
\usepackage{showframe}

    % Replace \autodot with "." for \section headings
\xpretocmd{\sectionformat}{\def\autodot{.}}{}{\cfPatchFailed} 
    % Section heading font settings
\addtokomafont{sectioning}{\linespread{1}\selectfont}
\setkomafont{section}{\Large}
\setkomafont{subsection}{\large}
\setkomafont{subsubsection}{\normalsize}

    % Spacing of section headings
\RedeclareSectionCommands[
    beforeskip=-5pt,
    afterskip=5pt
]{section,subsection,subsubsection}

% Following just makes the headings lines visible for debugging
\xpretocmd{\sectionformat}{\makebox[0pt][l]{\color{yellow}\rule[-\dp\strutbox]{\linewidth}{\baselineskip}}}{}{}
\xpretocmd{\subsectionformat}{\makebox[0pt][l]{\color{yellow}\rule[-\dp\strutbox]{\linewidth}{\baselineskip}}}{}{}
\xpretocmd{\subsubsectionformat}{\makebox[0pt][l]{\color{yellow}\rule[-\dp\strutbox]{\linewidth}{\baselineskip}}}{}{}

\begin{document}
\onehalfspacing
\KOMAoptions{DIV=current}

\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\subsection{Subsection}
\section{Section}

\makebox[0pt][l]{\color{yellow}\rule[-\dp\strutbox]{\linewidth}{\baselineskip}}%
\lipsum[1][1-5]
\makebox[0pt][l]{\color{yellow}\rule[-\dp\strutbox]{\linewidth}{\baselineskip}}%
Last line of the paragraph.

\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\subsection{Subsection}
\section{Section}
\end{document}

在此处输入图片描述

我添加了一些黄色背景来直观地显示普通文本和标题的行高和深度。

相关内容