# Drawing horizontal line same width as the page width

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.

-

## migrated from stackoverflow.comJun 4 '11 at 19:33

This question came from our site for professional and enthusiast programmers.

–  Caramdir Jun 4 '11 at 19:37

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.

-
I've seen this answer several times and I like it. It's a clever use of \leaders. –  TH. Jun 4 '11 at 23:59

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}}

-
doesn't \rule{\textwidth}{1pt} alone works? –  henrique Jun 4 '11 at 19:35
@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 4 '11 at 19:39