9

I am trying to decorate page numbers of my book with pgfornaments for sake of style.

Here is the code I am using:

\documentclass{extreport}
\usepackage{lipsum}
\usepackage{pgfornament} 
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}  
\fancyhead{}  
\fancyfoot{}  
\cfoot{\pgfornament[scale=0.25]{11} \thepage\ \pgfornament[scale=0.25]{14}}
\begin{document}
\lipsum[1]
\end{document}

Here is my result:

enter image description here

My question: how can I move the ornaments slightly upwards, so the ornament is aligned with the middle of the height of the page number? I would like to have it symmetrical.

1
  • 1
    You can use the raisebox macro... Commented Sep 26, 2017 at 6:05

4 Answers 4

12

One can raise the ornaments using a \vcenter{\hbox{...}} approach. That way, the ornaments will be placed on the (implicit) math axis.

A couple of style-related comments: (i) If you provide this type of ornaments, I think you should use a font that uses old-style numerals -- at least for the page numbers. (ii) I'd also provide a bit more space between the ornaments and the page numbers, e.g., with the help of \quad statements. Otherwise, the page number block risks looking, well, too "blocky".

enter image description here

\documentclass{extreport}
\usepackage{pgfornament,cfr-lm}
\newcommand{\myraise}[1]{$\vcenter{\hbox{#1}}$}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\fancyhead{}
\fancyfoot{}
\cfoot{\myraise{\pgfornament[scale=0.25]{11}}\quad%
       \thepage\quad\myraise{\pgfornament[scale=0.25]{14}}}

\begin{document}
\setcounter{page}{316}
\null % make sure document isn't entirely empty
\end{document}

Addendum: If you wish to use the cfr-lm font package while using oldstyle numerals only for the page numbers (and, hence, "lining" numerals everywhere else in the document), I suggest you add the following instructions to the preamble:

\usepackage[rm={lining,tabular},sf={lining,tabular},tt={lining,tabular}]{cfr-lm}
\renewcommand\thepage{\textpo{\arabic{page}}} 

That way, lining/tabular numerals will be the default everywhere except for page numbers, for which oldstyle/proportional numerals will be in use.

4
  • Thank you very much for the solution! I was using Old_Standard font. I see that you suggest to use cfr-lm for old­style dig­its, is that right? Could you kindly advice how to use this font for page numbers only ? I would like to stick with Old_Standard for text.
    – user136555
    Commented Sep 26, 2017 at 7:05
  • @user136555 - I was using the cfr-lm package mainly because it provides easy access to oldstyle numerals. I'm not very familiar with OldStandard, but I'm not sure it even provides oldstyle numerals. (At least, the OpenType version of the font doesn't seem to provide an onum option.) Can you confirm?
    – Mico
    Commented Sep 26, 2017 at 7:29
  • Sorry, if I am not very clear. Frankly, I think your suggestion, i.e. cfr-lm package for numerals is excellent and I really like it! How can I specify cfr-lm to be applied only for page numbers? Thank you.
    – user136555
    Commented Sep 26, 2017 at 7:36
  • @user136555 - I've posted an addendum to show how to load the cfr-lm font package in a way that makes lining/tabular numerals the default everywhere, while using oldstyle/proportional numerals for page numbers.
    – Mico
    Commented Sep 26, 2017 at 7:52
11

The ornament sits symmetrically on the baseline, which is good for deciding how much to raise it in your case.

Assuming you use lining figures, the amount of raising is exactly half the height of a figure in the current font.

\documentclass{article}
\usepackage{pgfornament}

\newcommand{\figureornament}[2][1]{%
  \raisebox{.5\fontcharht\font`0}{%
    \pgfornament[scale=#1]{#2}%
  }%
}

\begin{document}

\figureornament[0.25]{11} 317 \figureornament[0.25]{14}

\end{document}

It's immaterial whether you use that in \cfoot.

enter image description here

3

You can use the \raisebox command.

\raisebox{distance}[extend-above][extend-below]{text}

The \raisebox command is used to raise or lower text. The first mandatory argument specifies how high the text is to be raised (or lowered if it is a negative amount). The text itself is processed in LR mode.

Sometimes it's useful to make LaTeX think something has a different size than it really does - or a different size than LaTeX would normally think it has. The \raisebox command lets you tell LaTeX how tall it is.

The first optional argument, extend-above, makes LaTeX think that the text extends above the line by the amount specified. The second optional argument, extend-below, makes LaTeX think that the text extends below the line by the amount specified.

Source

In this case, wrap your \pgfornament command in a \raisebox, and adjust the distance value until it looks right. For example,

\raisebox{3pt}{\pgfornament[scale=0.25]{11}}
1
  • Thank you for the idea! I have tested and it works, 5pt are needed to align the glyph (by some strange reason, there are no glyphs at page 1 and 4 of the book). Out of pure curiosity - are there more "automated" ways of decorating page numbers with ornaments?
    – user136555
    Commented Sep 26, 2017 at 6:50
3

Interesting. I tried a purely TikZ approach:

\documentclass{extreport}
\usepackage[pass,showframe]{geometry}
\usepackage{pgfornament}
\usepackage[rm={lining,tabular},sf={lining,tabular},tt={lining,tabular}]{cfr-lm}

\renewcommand\thepage{\textpo{\arabic{page}}}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\fancyhead{}
\fancyfoot{}
\cfoot{%
    \tikz[baseline]{%
        \node[anchor=east] at (0,0){\pgfornament[scale=0.25]{11}};
        \node[anchor=center] at (0.5,0) {\thepage};
        \node[anchor=west] at (1,0) {\pgfornament[scale=0.25]{14}};
    }%
}

\begin{document}
\noindent This is some text with lining 123,456,789.0 numerals.
\setcounter{page}{1234}
\null % make sure document isn't entirely empty
\end{document}

This has the advantage that it is not necessary to juggle the ornaments or page number up and down -- TikZ does that by aligning the east,center and west anchors of the nodes. Moreover the placement of the the page number is exactly in the middle of the coordinates for the two ornaments, again thanks to TikZ. This might not work in all cases, but seems to in this case.

Output

Just a thought.

You must log in to answer this question.

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