1

How do I move some chosen text (or current page number) directly above the horizontal rule/line created by the \renewcommand{\footrulewidth} command?

I am using the fancyhdr package.

Edit: More specifically --- How can I keep the page number below the rule, but add some text (e.g. a URL) above the line?

1

1 Answer 1

1

In a comment has been required to have the page number centered below the footrule and a URL also centered, but above the footrule. Here's one possibility:

\documentclass{article}
\usepackage[a5paper]{geometry}% just for the example
\usepackage{fancyhdr}
\usepackage{url}
\usepackage{lipsum}% just to generate text for the example

\addtolength\footskip{10pt}
\newcommand\myurl{\url{www.ctan.org}}
\makeatletter
\def\@fancyfoot#1#2#3#4#5{#1\hbox to\headwidth{\fancy@reset
    \@fancyvbox\footskip{\hbox{\parbox[t]{\headwidth}{\centering\myurl}}\vskip.2\footskip\footrule
      \hbox{\rlap{\parbox[t]{\headwidth}{\raggedright#2}}\hfill
        \parbox[t]{\headwidth}{\centering#3}\hfill
        \llap{\parbox[t]{\headwidth}{\raggedleft#4}}}}}#5}
\makeatother

\fancyhf{}
\renewcommand\footrulewidth{0.4pt}
\renewcommand\headrulewidth{0pt}
\fancyfoot[C]{\thepage}
\pagestyle{fancy}

\begin{document}
\lipsum[1-20]
\end{document}

enter image description here

With the help of the etoolbox package, one can patch the \@fancyfoot command and the code simplifies:

\documentclass{article}
\usepackage[a5paper]{geometry}% just for the example
\usepackage{fancyhdr}
\usepackage{url}
\usepackage{etoolbox}
\usepackage{lipsum}% just to generate text for the example

\addtolength\footskip{10pt}
\newcommand\myurl{\url{www.ctan.org}}

\makeatletter
\patchcmd{\@fancyfoot}{\footrule}{\hbox{\parbox[t]{\headwidth}{\centering\myurl}}\vskip.2\footskip\footrule}{}{}
\makeatother

\fancyhf{}
\renewcommand\footrulewidth{0.4pt}
\renewcommand\headrulewidth{0pt}
\fancyfoot[C]{\thepage}
\pagestyle{fancy}

\begin{document}
\lipsum[1-20]
\end{document}
4
  • Thanks. How can I, keep the page number below the rule, but add some text (e.g. a URL) above the line. I tried to use \cfoot{\thepage} but then my text (above the line) disappeared
    – Sean
    Apr 1, 2013 at 1:42
  • @Sean And in what position should the number and the URL be? Both centered, number centered, URL to the left? Apr 1, 2013 at 1:44
  • Both should be centered
    – Sean
    Apr 1, 2013 at 1:49
  • @Sean please see my updated answer. I would also suggest you to add the complete description of the problem as an edit to your question, so it will be clear for everyone reading the question. Apr 1, 2013 at 2:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .