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.

1

2 Answers 2

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.

1
  • I've seen this answer several times and I like it. It's a clever use of \leaders.
    – TH.
    Jun 4, 2011 at 23:59
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}} 
2
  • 2
    doesn't \rule{\textwidth}{1pt} alone works?
    – henrique
    Jun 4, 2011 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 4, 2011 at 19:39

You must log in to answer this question.

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