如何在 LaTeX 中给章节标题加下划线?
编辑:正如我在第一个答案中看到的,下划线是错误的词。我想要在节标题下划一条线,将标题与以下文本分开。
我想用水平线将章节标题与以下文本分开。目前我使用以下内容:
\newcommand{\tmpsection}[1]{}
\let\tmpsection=\section
\renewcommand{\section}[1]{\tmpsection{#1}\hrule\nobreak}
但这会产生一条线,距离节标题太远,并且距离以下文本太近。有人有更好的主意吗?
EDIT: As I see in the first answer, underline is the wrong word. I want a line under the section heading, separating the heading from the following text.
I want to separate section headings from the following text with a horizontal line. At the moment I use the following:
\newcommand{\tmpsection}[1]{}
\let\tmpsection=\section
\renewcommand{\section}[1]{\tmpsection{#1}\hrule\nobreak}
But that produces a line, that is too far away from the section-heading and to near to the following text. Has anyone a better idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我听说
titlesec
比sectsty
包更强大,所以我就使用了它。您可以使用以下命令将水平线放在节标题之前:或者可以在 newcommand 的帮助下将其放在节标题之后。
请参阅titlesec 手册的第 4.4 节。
I've heard that the
titlesec
is more powerful thansectsty
package, so I've just used it. You can put the horizontal line before the section header using:or you can put it after, with the help of newcommand.
See section 4.4 of the titlesec manual.
像这样重写你的命令应该可以解决问题:
这将评估结果,从而
产生带下划线的部分标题:)
Rewriting your command like this should do the trick:
This will evaluate to
which in turn produces underlined section headings :)
您可以使用 sectsty 包。
You can do this with the
\sectionrule
command in the sectsty package.您可能会看一下 LaTeX
\rule
命令:但是,这是一个内联(水平)命令,因此您必须使用一些技巧才能使其处于正确的位置和大小(
\noindent
和\textwidth
应该有一点帮助)。否则,您可以使用以下纯 TeX
它并不真正适合 LaTeX 语法,但它的工作方式就像一个魅力,并且保证跨越整个文本宽度。
You might take a look at the LaTeX
\rule
command:However, that's an inline (horizontal) command, so you'll have to use some trickery to get it at the right position and size (
\noindent
and\textwidth
should help a little).Otherwise, you can use the following plain TeX
It doesn't really fit in the LaTeX syntax, but it works like a charm, and is guaranteed to span the entire text width.
另一种方式可能是:
Another way could be:
使用
titlesec
包,您可以在\titleformat
命令的最后添加方括号,以在节标题后插入内容(请参阅 titlesec 文档)。例如:Using the
titlesec
package, you can add square brackets at the very end of the\titleformat
command to insert something after the section-heading (see section 3.1 of the titlesec documentation). For example: