ConTeXt:如何防止章节标题中的 \hrule 之后出现新段落?

ConTeXt:如何防止章节标题中的 \hrule 之后出现新段落?

我正在使用 ConTeXt,并尝试将文档的子部分标题设置为以彩色规则开头。但是,无论我如何尝试,结果都是规则位于标题文本上方一行。

说明该问题的最简单的文档如下:

\startmode[*mkii]
  \enableregime[utf-8]
  \setupcolors[state=start]
\stopmode

\setuphead[section]      [style=\tfb, before={beforetext}]
\setuphead[subsection]   [style=\tfb, before={\blackrule}]

\starttext

\section{Section}
This works as expected.

\subsection{Subsection}
Here, for some reason the rule doesn't come on the same line as the heading.
However, inlining does seem to work in the section text: \blackrule
\stoptext

渲染为

规则渲染测试

有谁知道当规则是节标题的一部分时什么原因导致换行,以及如何防止这种情况发生?

答案1

您需要\leavevmode在规则之前明确说明:

\startmode[*mkii]
  \enableregime[utf-8]
  \setupcolors[state=start]
\stopmode

\setuphead[section]   [style=\tfb, before={beforetext}]
\setuphead[subsection][style=\tfb, before=\leavevmode\blackrule]

\starttext

\section{Section}
This works as expected.

\subsection{Subsection}
Here, for some reason the rule doesn't come on the same line as the heading.
However, inlining does seem to work in the section text: \blackrule
\stoptext

相关内容