283

I have used the \hrulefill command to create a horizontal rule, along with some other commands. In each case I have the rules extended up to the margin.

I want the rule width to be controllable, i.e. I want them to span the entire page. How can this be done? The existing help on Internet looks pretty scarce. Thanks for your help.

Gonzalo Medina
  • 505,128

6 Answers6

263

To get horizontal lines of any fixed length you can use the \rule command. To get a horizontal line spanning the whole page width you can use a \makebox command and then a \rule with a width equal to \paperwidth:

\documentclass{article}

\begin{document}

Below is a Line spanning the entire width of the page

\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

Below is a 2cm long line

\noindent\rule{2cm}{0.4pt}

Below is a 4cm long line

\noindent\rule{4cm}{0.4pt}

Below is a 8cm long line

\noindent\rule{8cm}{0.4pt}

\end{document}

Output: enter image description here Rules in LaTeX are 0.4pt "thick", by default.

puk
  • 3,061
  • 5
  • 30
  • 41
Gonzalo Medina
  • 505,128
  • 6
    Maybe you could also include a rule of length \textwidth, for comparison with the one of \paperwidth placed in a '\makebox`. – Davor Cubranic Sep 01 '16 at 18:33
  • Is there a way to modify this to set the top and bottom margin/padding of the line? It could be useful to set the space between paragraphs above and below, respectively. – tukusejssirs Apr 26 '19 at 18:57
162

Another option is this one, which makes a horizontal line stretch the entire page. I prefer this one, because it's short, easy to remember and exactly what I need. I hope this works for you too.

\noindent\rule{\textwidth}{1pt}
Majora320
  • 103
martijnn2008
  • 1,877
20

I used the \line command: \line(x slope, y slope){length}.

\begin{center}
\line(1,0){450}
\end{center}
Werner
  • 603,163
  • 2
    It was useful for me to define it as its own command: \newcommand{\hr}{\begin{center} \line(1,0){450} \end{center}}. – NuclearPeon Dec 29 '16 at 21:17
6

\underline{\hspace{ x in}} gives you a line of length x inches.

carlos
  • 61
  • 3
    Welcome to TeX.SX! Don't be so chatty! ;-) I don't think that this answers the (old) question –  Sep 26 '14 at 14:07
3

Old question, but the most voted answer doesn't really solve the problem.

\documentclass{book}

\usepackage[a6paper]{geometry}% just to make a smaller picture

\begin{document}

\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\clearpage

\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}

\end{document}

enter image description here

You can note that the rule does not cover the whole paper width, because the margins are asymmetric. The trick only works if the margins are equal.

The real solution is very simple: use 2\paperwidth. The PDF translation will truncate the part that goes beyond the MediaBox. Even better, use \maxdimen, so there aren't edge cases for sure.

\documentclass{book}

\usepackage[a6paper]{geometry}% just to make a smaller picture

\begin{document}

\noindent\makebox[\linewidth]{\rule{\maxdimen}{0.4pt}}

\clearpage

\noindent\makebox[\linewidth]{\rule{\maxdimen}{0.4pt}}

\end{document}

enter image description here

egreg
  • 1,121,712
0

Attending the horizontal line problem I used the \rule as other has mentioned. Although, if you want to have a centered line that separates your paragraphs you can use this simple code. You can add another \bigskip in order to add empty spacing :)

    \documentclass{article}
    \begin{document}
Some random text above \\

\centerline{\rule{13cm}{0.4pt}}
\bigskip

Some random text below 

\end{document}

Mensch
  • 65,388
Lauge
  • 61