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 use fancyhdr to customize my footer. But this code:

\pagestyle{fancy}
\fancyhf{} % sets both header and footer to nothing
\lfoot{From: K. Grant}
\rfoot{\thepage}
\renewcommand{\footrulewidth}{0.4pt}

adds TWO rulers (top and bottom) with the width that is equal to the page width. I would like to reduce the width of the bottom ruler to the width of the main text and remove the top ruler. Plus, I would like the width of the text below the bottom ruler to be the same as the width of the main text. How to do this?

UPDATE: I forgot to mention that I also use geometry package to adjust page margins. Maybe this is the source of the problem?

UPDATE

\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage{longtable}
\usepackage[top=2cm, bottom=2cm, left=1.5, right=1cm]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}


\fancyhf{} % sets both header and footer to nothing
\lfoot{Page \thepage}
\rfoot{some text}
\renewcommand{\footrulewidth}{0.4pt}
\renewcommand{\headrulewidth}{0pt}

\begin{document}

SOME TEXT SOME TEXT SOME TEXT SOME TEXT  
SOME LOOOOONG TABLE

\end{document}
share|improve this question
    
Does your footer rule actually stretch from the left to the right page border? –  Werner Nov 30 '11 at 19:36
    
@Yes, it does. P.S. See update in the question statement –  Physicsworks Nov 30 '11 at 19:46
    
While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages. –  Peter Grill Nov 30 '11 at 19:55
    
Thanks, but you really should check that it compiles first. –  Peter Grill Nov 30 '11 at 20:21
1  
@Physicsworks: If you don't specify a unit, it defaults to pt (I think). As such, your left margin is actually set to 1.5pt, not 1.5cm. That gives the illusion that the rule spans the entire page width. –  Werner Nov 30 '11 at 22:54

3 Answers 3

up vote 2 down vote accepted

To disable the header rule, just add to your preamble

\renewcommand{\headrulewidth}{0.0pt}

Note that by default the start of a paragraph is indented, so it appears that the horizontal rule is longer than the text:

enter image description here

But, once you add some additional text (here I have used the \lipsum package to provide dummy text), you can see that width of the rule from fancyhdr is the full text width:

enter image description here

This code is a corrected version of your MWE, with additional dummy text:

\documentclass[12pt]{article}
\usepackage{lipsum}

\usepackage[utf8]{inputenc}
\usepackage{longtable}
\usepackage[top=2cm, bottom=2cm, left=1.5cm, right=1cm]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}


\fancyhf{} % sets both header and footer to nothing
\lfoot{Page \thepage}
\rfoot{some text}
\renewcommand{\footrulewidth}{0.4pt}
\renewcommand{\headrulewidth}{0pt}

\begin{document}

SOME TEXT SOME TEXT SOME TEXT SOME TEXT  
SOME LOOOOONG TABLE
\lipsum

\end{document}
share|improve this answer
    
FINALLY, this works perfectly! Thanks, +1 to this. –  Physicsworks Nov 30 '11 at 20:52

I suppose that you load package geometry after package fancyhdr. Change the order, otherwise you'll get wrong margins for the header/footer

share|improve this answer
    
Actually, I've tried BOTH ways with the same final result... Any other ideas? –  Physicsworks Nov 30 '11 at 19:52
    
no, that's not possible. Then you have something different, which changes the margings after loading fancyhdr. Create a minimal and complete example and you'll find yourself what's wrong. Or show it here. –  Herbert Nov 30 '11 at 20:03
    
There is NO difference in the order of packages. I'll add the full code in a few minutes –  Physicsworks Nov 30 '11 at 20:12

In terms of removing the top (or header) rule, use

\renewcommand{\headrulewidth}{0pt}

This is what the output looks like in a minimal document:

enter image description here

\documentclass{article}
\usepackage[left=0.5in,right=1in]{geometry}% http://ctan.org/pkg/geometry
\usepackage{fancyhdr}% http://ctan.org/pkg/fancyhdr
\pagestyle{fancy}
\fancyhf{} % sets both header and footer to nothing
\lfoot{From: K. Grant}
\rfoot{\thepage}
\renewcommand{\headrulewidth}{0pt}% remove header rule
\renewcommand{\footrulewidth}{0.4pt}
\begin{document}
\null \vfill Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Aenean faucibus auctor neque, quis vulputate purus facilisis et. 
\end{document}​

As you can see, the width of the footer (or header for that matter), including the rule, is the same as the text width (\textwidth), by default. As @Herbert suggests, you need to load geometry before you set any of the fanchdr settings. Here's what the output looks like if the order was reversed:

enter image description here

\documentclass{article}
\usepackage{fancyhdr}% http://ctan.org/pkg/fancyhdr
\pagestyle{fancy}
\fancyhf{} % sets both header and footer to nothing
\lfoot{From: K. Grant}
\rfoot{\thepage}
\renewcommand{\headrulewidth}{0pt}% remove header rule
\renewcommand{\footrulewidth}{0.4pt}
\usepackage[left=0.5in,right=1in]{geometry}% http://ctan.org/pkg/geometry
\begin{document}
\null \vfill Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Aenean faucibus auctor neque, quis vulputate purus facilisis et. 
\end{document}​
share|improve this answer
    
to show the effect you need two lines of text and not a complete page ... –  Herbert Nov 30 '11 at 19:44
    
Thanks, but this is the same code I have. Maybe the problem is that I use geometry package (see update in the question statement)? –  Physicsworks Nov 30 '11 at 19:44
    
@Werner: Perhaps include a margin adjustment in the geomtry settings, and I can delete my answer. Also, I did not see any difference in the order of the package loading. –  Peter Grill Nov 30 '11 at 20:05
    
@PeterGrill: Good suggestion - done. –  Werner Nov 30 '11 at 20:15

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.