How to underline section-headings in LaTeX?

*爱你&永不变心* 提交于 2019-12-05 20:35:54

问题


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?


回答1:


You can do this with the \sectionrule command in the sectsty package.




回答2:


Rewriting your command like this should do the trick:

\newcommand{\tmpsection}[1]{}
\let\tmpsection=\section
\renewcommand{\section}[1]{\tmpsection{\underline{#1}}}

This will evaluate to

\section { \underline {#1} }

which in turn produces underlined section headings :)




回答3:


I've heard that the titlesec is more powerful than sectsty package, so I've just used it. You can put the horizontal line before the section header using:

\usepackage{titlesec}
\titleformat{\section}{\large\bfseries}{\thesection}{1em}{\hrule}

or you can put it after, with the help of newcommand. See section 4.4 of the titlesec manual.




回答4:


You might take a look at the LaTeX \rule command:

\rule[raise-height]{width}{thickness}

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

\smallskip
\hrule height 2pt
\smallskip

It doesn't really fit in the LaTeX syntax, but it works like a charm, and is guaranteed to span the entire text width.




回答5:


Another way could be:

\begin{center}
\line(1,0){400}
\end{center}


来源:https://stackoverflow.com/questions/1392614/how-to-underline-section-headings-in-latex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!