1

I'm using fancyhdr to set the page numbering to the right op the page and display 1/2 for "page 1 of 3".

I would now like to customize the design of this. There should be a horizontal line, centered vertically relative to the page number and going from the very left of the \linewidth to the page number:

|                                                 |
|-------------------------------------------- 1/3 |
|                                                 |

Unfortunately, I don't get this result. Party the cause for this will be, that fancyhdr makes three columns in the footer, so the end (or in this case the start) of the text line would be the starting point of the column and so, the line would only spread to a third of the page, but I don't even get that going.


How could I modify my code, to have that line spreading across the whole width of the text line, not only across the width of one column?


MWE

\documentclass{article}
\usepackage{xhfill}
\usepackage{fancyhdr}
\usepackage{lastpage}

\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyfoot[R]{\xrfill[0.5ex]{1pt}~\thepage/\pageref{LastPage}}

\AtBeginDocument{
    \pagestyle{fancy}
}

\begin{document}        
    \noindent This is the output I want:\par
    \noindent\xrfill[0.5ex]{1pt}~1/1
\end{document}
2

Just add \leavevmode:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe]{geometry}
\usepackage{xhfill}
\usepackage{fancyhdr}
\usepackage{lastpage}

\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyfoot[R]{\leavevmode\xrfill[0.5ex]{1pt}~\thepage/\pageref{LastPage}}

\AtBeginDocument{
    \pagestyle{fancy}
}

\begin{document}

    \noindent This is the output I want:\par
    \noindent\xrfill[0.5ex]{1pt}~1/1

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.