Sign up ×
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

3 Answers 3

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

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

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

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.
http://tex.stackexchange.com/questions/94688/page-numbering-in-the-middle-of-a-line
tex.stackexchange.com
crawl=CC-MAIN-2015-40
81299
application/http; msgtype=response
sha1:RDHINWK7HIBDFZXG4VGE2ZTIE2BWOA4N
<urn:uuid:e3d96373-cfbc-4376-a968-0734009e5c7f>
2015-10-05T15:19:05Z
104.16.12.128
sha1:WZKSXFOOC7Z2GXXTLQID2KQPFXLDSPUC
<urn:uuid:136af3fd-b1b0-46c3-9123-37dcba7f0ad6>
http://tex.stackexchange.com/questions/94688/page-numbering-in-the-middle-of-a-line
length
response
<urn:uuid:c1467ae6-1a33-48f8-93bd-8420a785fdf4>
robots: classic
hostname: ip-10-137-6-227.ec2.internal
software: Nutch 1.6 (CC)/CC WarcExport 1.0
isPartOf: CC-MAIN-2015-40
operator: CommonCrawl Admin
description: Wide crawl of the web for September 2015
publisher: CommonCrawl
format: WARC File Format 1.0
conformsTo: http://bibnum.bnf.fr/WARC/WARC_ISO_28500_version1_latestdraft.pdf