6

I've been trying to draw a line with width the same as the page width. I use fancyhdr and I have a line for my footer, and I want the their widths to be equal.

I tried \line(1, 0){\textwidth} and \line(1,0){\pagewidth} but no luck. I know I can use \line(1,0){450} for example, but that means I would have to play around and find the exact page width.

lockstep
  • 250,273
kkudi
  • 525
  • See also http://tex.stackexchange.com/questions/19579/horizontal-line-spanning-the-entire-document-in-latex – Caramdir Jun 04 '11 at 19:37

2 Answers2

13

To get a line from one margin to the other, use

\noindent\makebox[\linewidth]{\rule{\textwidth}{1pt}} 

To get a line from one end of the page to the other, use

\noindent\makebox[\linewidth]{\rule{\paperwidth}{1pt}} 
Lorem Ipsum
  • 1,346
  • 1
  • 7
  • 22
  • 2
    doesn't \rule{\textwidth}{1pt} alone works? – henrique Jun 04 '11 at 19:35
  • 5
    @henrique @yoda \rule, if given between paragraphs, adds the normal indent. The use of \linewidth is correct and does not give overfull boxes, but it should be \makebox[\linewidth][r]{...}. – egreg Jun 04 '11 at 19:39
12

Assuming that the rule is needed in "normal" places of the document, i.e. not in list environments or other special places, the most efficient way is

\vskip\medskipamount % or other desired dimension
\leaders\vrule width \textwidth\vskip0.4pt % or other desired thickness
\vskip\medskipamount % ditto
\nointerlineskip

Sensible values for the vertical spaces are \smallskipamount, \medskipamount, \bigskipamount or \topsep; it can be given also explicitly.

Such a rule will vanish should it fall at the bottom or at the top of a page, together with the spaces.

egreg
  • 1,121,712
  • I've seen this answer several times and I like it. It's a clever use of \leaders. – TH. Jun 04 '11 at 23:59