# How to reduce horizontal ruler's width to the width of the document text in fancyhdr?

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}

\begin{document}

SOME TEXT SOME TEXT SOME TEXT SOME TEXT
SOME LOOOOONG TABLE

\end{document}

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

\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:

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:

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}

\begin{document}

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

\end{document}

-
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

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

\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{\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:

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

@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