108

Horizontal line picture

How can I draw this horizontal line like this picture in Latex? Thanks for your help.

7
  • 12
    You mean \hrule? That should be what you're looking for
    – Moriambar
    May 23, 2017 at 19:13
  • 2
    As opposed to \rule{\textwidth}{0.5pt} which is treated like wide character rather than a tiny paragraph. May 23, 2017 at 19:33
  • 2
    If by chance this rule is supposed to be above a code listing as in the screenshot, then you could also see whether the environment you use for the code has the possibility to add it. Both minted and listings have this feature, for example. (@Moriambar Why don't you just add an answer instead of voting to close?) May 24, 2017 at 19:15
  • @TorbjørnT. good idea
    – Moriambar
    May 24, 2017 at 19:17
  • 2
    Note also that \hrulefill will extend the line to the right margin of the current scope, so that you can avoid specifying a length. Oct 12, 2017 at 13:05

1 Answer 1

166

I see two choices, one using \rule (as suggested by @John Kormylo) and one using \hrule. I'll describe them both and give an example at the end


The \rule command constructs a box, which is treated like a character and has the following syntax \rule[h]{w}{t} where h w and t are lengths and represent respectively:

  • the height above the baseline to which raise the box (defaults at 0)

  • the width of the box

  • the thickness of the rule

In your case

\par\noindent\rule{\textwidth}{0.4pt}

should do the trick.


The \hrule command is a TeX primitive and is a bit more complicated to use because it suppresses the interline spacing. Its full syntax is as follows:

\hrule height h depth d width w \relax

where h, d and w should be substituted with the appropriate lengths (height is the thickness of the rule). Any order of height depth and width are supported, and any or all of them can be left out, which will make TeX use the following defaults:

  • height will be 0.4 pt

  • depth will be 0pt

  • width will make the rule extend to the boundary of the outer box.

Usually hrule is to be used between paragraphs, otherwise it will start or stop a paragraph. The \relax is not always needed, but it prevents the misinterpretation of following words and numbers when there is ambiguity

Note sometimes it's useful to use \vspace before or after the \hrule to space it from the previous and next paragraphs. In this case I don't know the specifics of the problem to determine the proper spacing of the rule suitable for you.


Example (the \vspaces are random)

\documentclass{article}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\vspace{5pt}
\hrule
\vspace{6pt}
\lipsum[1]
\noindent
\rule{\textwidth}{0.4pt}
\end{document}

enter image description here

4
  • I had gotten stuck making the footnoterule to the right:
    – Bryan H-M
    Oct 16, 2018 at 19:42
  • +1 for using \rule for custom line thickness
    – theo-brown
    Aug 26, 2021 at 15:02
  • This answer is wrong or outdated. As my provided answer proves, \hrule is not "a bit more complicated to use". In fact, it does not requires any argument, so it is the more simple to use that any command can get. Jul 2, 2023 at 15:26
  • 6
    @BsAxUbx5KoQDEpCAqSffwGy554PSah No, your answer is extremely incomplete, (not to mention simply giving a link) and this answer is entirely correct. \hrule is a TeX primitive, and so not actually a LaTeX command, and so its behaviour isn't as you might expect since it removes the interline spacing. And it does take the arguments shown in the answer. But, as the example code here shows, it can be used without any arguments, as well since the example here is almost identical to the one in your link.
    – Alan Munn
    Jul 2, 2023 at 16:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .