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{}
\fancyhead[c]{\begin{tabular}{c}\hspace{1in}\textsc{\mytitle}\hspace*{1in}\\\hline\end{tabular}}
\renewcommand{\headrulewidth}{0pt}
\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
\def\headrule{\nointerlineskip\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi%
{\hfil\rule{0.5\headwidth}{\headrulewidth}} \vskip-\headrulewidth}
\makeatother
in order to stay as close to the original definition made by fancyhdr
as possible.
Best Answer
Use the optional argument of
\rule
to shift the line up/down:\rule[shift]{width}{length}