# FancyHdr top rule that is not full width

By default, fancyhdr includes a headrule separator line that spans the text width at the top of the page. Is there a (simpler) way to get the headrule (or footrule, for that matter) to span only, say, 50% of the text width?

For instance, consider this MWE that does (roughly) what I've asked using a tabular to add a line manually with a little space around the title itself:

\documentclass[12pt]{article}

\newcommand\mytitle{Title of Document}

\usepackage{fancyhdr}
\fancyhf{}
\pagestyle{fancy}

\usepackage{blindtext}
\begin{document}
\blinddocument
\end{document}


Is there a more straightforward way to accomplish this? The ideal solution would not be dependent on the length of the title, and would have an adjustable width in terms of percentage of the \textwidth dimension.

## Epilogue

I ended up using

\makeatletter
\makeatother


in order to stay as close to the original definition made by fancyhdr as possible.

-

\documentclass[12pt]{article}
\newcommand\mytitle{Title of Document}
\usepackage{fancyhdr}
\fancyhf{}
\pagestyle{fancy}

\usepackage{blindtext}
\begin{document}
\blinddocument
\end{document}


Use the optional argument of \rule to shift the line up/down: \rule[shift]{width}{length}

-
In fact, the height of the \makebox seems to add space between the title and the rule that is undesirable... – cslstr Jun 24 '14 at 12:43
Along with the addition of \nointerlineskip (see tex.stackexchange.com/a/186385), this does what I need. – cslstr Jun 24 '14 at 15:03
USe the optional argument, e.g.: \rule[1ex]{0.5\headwidth}{\headrulewidth} – Herbert Jun 24 '14 at 16:13

It's pretty easy to do using titlesec instead of fancyhdr: its titleps module has a\widenhead command that allows enlarging header rules (indenpendently on each side); a negative value will shrink the rule. It doesn-t add any vertical space. This supposes you don't want to write something on the left or right side of the header, but I don't see why you would with a short rule. Actually, you could still write on the sides but it would be more tricky.

Here is an example in which the header rule is exactly half textwidth wide:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{fourier, heuristica}

\usepackage[nomarginpar]{geometry}
\newcommand\mytitle{Title of Document}
\usepackage[pagestyles]{titlesec}
\newpagestyle{mine}{%
\setfoot{}{\thepage}{}
}

\pagestyle{mine}

\usepackage{blindtext}

\begin{document}

\blinddocument

\end{document}


You also can make ‘oldstyle’ headers, with a horizontal rule a little larger than the header, with this code. It uses the facilities of the makebox package:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{fourier,heuristica}
\usepackage{makebox}

\usepackage[nomarginpar]{geometry}
\newcommand\mytitle{Title of Document}
\usepackage[pagestyles]{titlesec}

\newpagestyle{thine}{%
\setfoot{}{\thepage}{\hrulefill}
}

\pagestyle{thine}

\usepackage{blindtext}

\begin{document}

\blinddocument

\end{document}


Result:

-
I considered this (actually, with the \fancyhfoffset option, which does essentially the same thing), but it breaks down in the case of \newcommand\mytitle{What if the Title of Document is Longer?}. – cslstr Jun 24 '14 at 13:57
I don't know well the details of fancyhdr, as I use titlesec for formatting section titles, so that I prefer to use a package of the same family, but it would have surprising it didn't have more or less the same functionalities… However I find titlesec/titleps easier to use on the whole. – Bernard Jun 24 '14 at 14:21
We all find what we are used to easier to use, don't we? Just why I started out with fancyhdr! :) – cslstr Jun 24 '14 at 14:32

Not sure what spacing you want, but something like

\documentclass[12pt]{article}
\newcommand\mytitle{Title of Document}
\usepackage{fancyhdr}
\fancyhf{}

\nointerlineskip was the key to the whole problem, for me at least. Adding this also enables the solution by @Herbert perform as it should. – cslstr Jun 24 '14 at 15:01