Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I set up a document to write the page numbering in the middle of a line?

Through fancy pagestyle I've got a situation like the following one:

--------------------- % this is a line after the body of my document
          1           % this is another line with the page number, centered

While I'd like to have a situation such as the following:

--------- 1 --------- % this is only a line after the body of my document

How can I do that? A first solution may involve tikz, but is it needed or there are other solutions?

share|improve this question
add comment

3 Answers

up vote 6 down vote accepted

I would take the \Vhrulefill macro for this (posted by Gonzalo Medina in Vertically centered horizontal rule filling the rest of a line?)

I appended a working example:

\documentclass{article}
\usepackage{fancyhdr}
\usepackage{lipsum}
\pagestyle{fancy}
\def\Vhrulefill{\leavevmode\leaders\hrule height 0.7ex depth \dimexpr0.4pt-0.7ex\hfill\kern0pt}
\fancyfoot{\Vhrulefill~\thepage~\Vhrulefill}
\begin{document}
\lipsum
\end{document}
share|improve this answer
2  
If you paste directly the link it will appear immediately the title of the question, which is more clear than here. :) –  Claudio Fiandrino Jan 21 '13 at 10:02
    
Thanks for the hint! –  user1146332 Jan 21 '13 at 10:02
add comment

A possible solution is based on the following packages:

Basically, by means of tikzpagenodes it is possible to access to current page footer area:

\newcommand{\myfooterstyle}[2][]{%
\tikz[remember picture,overlay]{%
   \draw[#1]
   ($(current page footer area.south west)!0.25!(current page footer area.north west)$)
   --
   ($(current page footer area.south)!0.25!(current page footer area.north)-(#2,0)$)
   ($(current page footer area.south)!0.25!(current page footer area.north)+(#2,0)$)
   --
   ($(current page footer area.south east)!0.25!(current page footer area.north east)$)
   ;
  }%
}

The mandatory argument specifies how much distant is the rule from the page number while the optional argument let you access possible customization like colors or rule width. Because of the options [remember picture, overlay] two compilation runs are necessary.

Then, by means of the background package, the command will be executed everytime:

\AddEverypageHook{%
\myfooterstyle{1em}
\BgMaterial}

The complete code:

\documentclass{article}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\usepackage[contents={}]{background}

\usepackage{lipsum}% for dummy text

\newcommand{\myfooterstyle}[2][]{%
\tikz[remember picture,overlay]{%
   \draw[#1]
   ($(current page footer area.south west)!0.25!(current page footer area.north west)$)
   --
   ($(current page footer area.south)!0.25!(current page footer area.north)-(#2,0)$)
   ($(current page footer area.south)!0.25!(current page footer area.north)+(#2,0)$)
   --
   ($(current page footer area.south east)!0.25!(current page footer area.north east)$)
   ;
  }%
}

\AddEverypageHook{%
\myfooterstyle{1em}
\BgMaterial}

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

How it looks:

enter image description here

share|improve this answer
add comment

Redefine your own style:

\renewcommand{\@evenfoot}%
    {\hfil\thepage\hfil}
\renewcommand{\@oddfoot}%
    {\hfil\thepage\hfil}
share|improve this answer
2  
And the line? It would be more useful for reader you explain what you are doing in your given code, for example the reader may not know @evenfoot (how to handle the @). –  Kurt Jan 21 '13 at 10:36
    
I've read post inattentive (deciding that "line" is a text line, not a rule). To make a rule just replace \hfil as above. Or even so: \def\hRfil{\leaders\hbox to 1pt{-}\hfil}, \renewcommand{\@oddfoot}{\hRfil\hbox to 2em{\hfil\thepage\hfil}\hRfil} –  Eddy_Em Jan 21 '13 at 11:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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