# PGFOrnaments don't center properly

I would like to have nice fleurons and decorations at the end of my chapters to mimic the style of a book from the late 1800's. Some searches brought pgfornaments to my attention (a more user friendly version of ps vectorian) as the ps decorations look fantastic – exactly what I was looking for.

At any rate, after playing around with it, I've found that centering the PS images produces quite terrible results (see the image below). I should note that these examples are larger than I would use in a real book, but they're enlarged to make it easier to see where the center of the image really is. Not only are the images not centered, but the offset isn't even consistent from image to image. That makes this package completely unusable...

Can someone with more experience tell me if the problem here is specific to pgfornament (the documentation claims it's still in beta) or if the problem is how the PS images themselves are created (i.e., should I try working directly with ps vectorian or will that have the same problem?). Is there some way to fix this so the centering environment works correctly with these objects?

% !TEX TS-program = xelatex
% !TEX encoding = UTF-8
% this allows us to use real characters like æ instead of macros like \ae

%% PREAMBLE
\documentclass[letterpaper,titlepage,twoside,openany,12pt]{book}

\usepackage{fontspec}
\setmainfont[Language=Icelandic, Fractions=On]{Junicode}
\newcommand{\jfd}{}    %\symbol{"E67D}}

%Switch implementation for end-of-chapter fleurons (below)
\usepackage{xifthen}
\newcommand{\ifequals}[3]{\ifthenelse{\equal{#1}{#2}}{#3}{}}
\newenvironment{switch}[1]{\renewcommand{\case}{\ifequals{#1}}}{}

\usepackage[object=vectorian]{pgfornament}
\newcommand{\chapterline}[1]{
\begin{center}
\Large\color{myred}
\begin{switch}{#1}
\case{1}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{80}}
\case{2}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{81}}
\case{3}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{82}}
\case{4}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{83}}
\case{5}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{84}}
\case{6}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{85}}
\case{7}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{86}}
\case{8}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{87}}
\case{9}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{88}}
\case{10}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{89}}
\end{switch}
\end{center}
}

%Define some colors for the fancy titles
\usepackage{color}
\definecolor{myblue}{rgb}{0,0,0.4}
\definecolor{myred}{rgb}{0.6,0,0}

\usepackage{titlesec}
\titleformat{\chapter}[display]
{\Huge\filcenter}
{
{\Large\color{myred}}\\[0.5cm]
\color{myblue}\chaptertitlename\ \thechapter\\[0.4cm]
\color{myred}\jfd
}
{0.4cm}
{\filcenter}
[\vspace{0.1cm}{\Large\color{myred}}]
\titlespacing*{\chapter}{0pt}{-50pt}{*2.0}

%Customize some margions and other lengths
\usepackage{geometry}
%Although shifted even/odd margins look nice for two sided
%printing, it's distracting when viewing the PDF.
\geometry{outer=1.1in,inner=1.1in}
\geometry{bindingoffset=0cm,hratio=1:1}
%the default bottom margin is huge, make it a bit smaller

\begin{document}
\mainmatter

\chapter[Test Ornaments]{Test Ornaments \\ Ornament Test}

\chapterline{1}

\chapterline{2}

\chapterline{3}

\chapterline{4}

\chapterline{5}

\chapterline{6}

\chapterline{7}

\chapterline{8}

\chapterline{9}

\chapterline{10}

\end{document}

• The problem is not with the package, but with your \chapterline command. – Gonzalo Medina Sep 3 '15 at 3:46
• The problem are the spurious spaces in the definition of \chapterline. There should be a % at the end of every line starting with \case. – Ulrike Fischer Sep 3 '15 at 6:46

You have a very rich supply of spurious spaces in your macro. With

\newcommand{\chapterline}[1]{%
\begin{center}
\Large\color{myred}
\begin{switch}{#1}%
\case{1}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{80}}%
\case{2}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{81}}%
\case{3}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{82}}%
\case{4}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{83}}%
\case{5}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{84}}%
\case{6}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{85}}%
\case{7}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{86}}%
\case{8}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{87}}%
\case{9}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{88}}%
\case{10}{\pgfornament[anchor=center,ydelta=0pt,width=5cm]{89}}%
\end{switch}
\end{center}
}


I get perfect centering.

A better implementation:

\newcommand{\chapterline}[1]{%
\begin{center}
\color{myred}
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{\the\numexpr79+#1}
\end{center}%
}


The problem lies in your definition of \chapterline (inherited probably from your definition of switch or \case (which I didn't quite understand)).

Below I used a standard \ifcase to define the command and got the desired result (I used TikZ to place a vertical rule at the middle of the text area just as a visual guide):

% !TEX TS-program = xelatex
% !TEX encoding = UTF-8
% this allows us to use real characters like æ instead of macros like \ae

%% PREAMBLE
\documentclass[letterpaper,titlepage,twoside,openany,12pt]{book}

\usepackage{fontspec}
%\setmainfont[Language=Icelandic, Fractions=On]{Junicode}
\newcommand{\jfd}{}    %\symbol{"E67D}}

\usepackage{tikzpagenodes}

\usepackage[object=vectorian]{pgfornament}
\newcommand{\chapterline}[1]{%
\begin{center}
\LARGE\color{myred}
\ifcase#1\relax
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{80}%
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{81}
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{82}
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{83}
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{84}
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{85}
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{86}
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{87}
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{88}
\or
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{89}
\else
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{90}
\fi
\end{center}
}

%Define some colors for the fancy titles
\usepackage{color}
\definecolor{myblue}{rgb}{0,0,0.4}
\definecolor{myred}{rgb}{0.6,0,0}

\usepackage{titlesec}
\titleformat{\chapter}[display]
{\Huge\filcenter}
{
{\Large\color{myred}}\\[0.5cm]
\color{myblue}\chaptertitlename\ \thechapter\\[0.4cm]
\color{myred}\jfd
}
{0.4cm}
{\filcenter}
[\vspace{0.1cm}{\Large\color{myred}}]
\titlespacing*{\chapter}{0pt}{-50pt}{*2.0}

%Customize some margions and other lengths
\usepackage{geometry}
%Although shifted even/odd margins look nice for two sided
%printing, it's distracting when viewing the PDF.
\geometry{outer=1.1in,inner=1.1in}
\geometry{bindingoffset=0cm,hratio=1:1}
%the default bottom margin is huge, make it a bit smaller

\begin{document}

\chapter[Test Ornaments]{Test Ornaments \\ Ornament Test}

% For testing
\begin{center}
\pgfornament[anchor=center,ydelta=0pt,width=5cm]{80}
\end{center}

\chapterline{1}

\chapterline{2}

\chapterline{3}

\chapterline{4}

\chapterline{5}

\chapterline{6}

\chapterline{7}

\chapterline{8}

\chapterline{9}

\chapterline{10}

% Just to test the centering
\begin{tikzpicture}[remember picture,overlay]
\draw[line width=2pt,cyan]
(current page text area.north) -- (current page text area.south);
\end{tikzpicture}
\end{document}