Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Jun 4 '11 at 19:33

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

    
See also tex.stackexchange.com/questions/19579/… –  Caramdir Jun 4 '11 at 19:37

2 Answers 2

up vote 9 down vote accepted

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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.