1

I'm trying to setup some corners ornamentations with the pgfornament package. It works, but the horizontal position of some of the ornamentations is wrong and I don't know how to push them properly. Here's a stripped down MWE version of my full castle of cards, that shows the issue:

\documentclass[11pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[nomath]{lmodern}
\usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot]{geometry}
\usepackage{microtype}
\usepackage[bottom]{footmisc}  % Options : [perpage], [symbol], [multiple]
\usepackage{mathtools}
\usepackage[dvipsnames,table]{xcolor}
\usepackage[pagestyles,medium]{titlesec}

% Main header :
\newpagestyle{principal}{
    \sethead[\thepage][][\itshape\small\MakeUppercase{\chaptername\ \thechapter. \chaptertitle}]{\itshape\small\MakeUppercase{\thesection\ \sectiontitle}}{}{\thepage}
    \headrule
}

% Add a gray border :
\usepackage{eso-pic}
\definecolor{colorMarge}{RGB}{242,242,245}
\newlength{\distance}
\setlength{\distance}{0.0in} % 0.5in
\newlength{\rulethickness}
\setlength{\rulethickness}{0.5in} % 1pt
\newlength{\ruleheight}
\setlength{\ruleheight}{\paperheight} % Longueur de la ligne
\newlength{\xoffset}
\newlength{\yoffset}
\setlength{\yoffset}{0pt} %{0.5\dimexpr\paperheight-\ruleheight}

\AddToShipoutPicture{%
    \setlength\fboxsep{1pt}% no additional frame for \colorbox
    \ifodd\value{page}%
        \setlength{\xoffset}{\distance}%
    \else
        \setlength{\xoffset}{\dimexpr\paperwidth-\rulethickness-\distance}%
    \fi
    \AtPageLowerLeft{%
        \put(\LenToUnit{\xoffset},\LenToUnit{\yoffset}){%
        \colorbox{colorMarge}{\parbox[b][\ruleheight][c]{\rulethickness}{%
        \centering
        \ifodd\value{page}%
            \rotatebox[origin=cB]{90}{\color{lightgray}{\strut \large{\normalfont\textsc{Name and year}}}}%
        \else
            \rotatebox[origin=cB]{90}{\color{lightgray}{\strut \huge{\normalfont\textsc{Book Title}}}}%
        \fi}}}}%
}

% Add ornementations to corners :
\usepackage[object=vectorian]{pgfornament}

\makeatletter
\AddToShipoutPicture{%
    \begingroup
    \setlength{\@tempdima}{2mm}%
    \setlength{\@tempdimb}{\paperwidth-\@tempdima-0.75in}%
    \setlength{\@tempdimc}{\paperheight-\@tempdima}%
    \put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdimc}){%
        \pgfornament[anchor=north west,width=0.75in,color=gray]{41}}
        \put(\LenToUnit{\@tempdima},\LenToUnit{\@tempdima}){%
        \pgfornament[anchor=south west,width=0.75in,symmetry=h,color=gray]{41}}
        \put(\LenToUnit{\@tempdimb},\LenToUnit{\@tempdimc}){%
        \pgfornament[anchor=north east,width=0.75in,symmetry=v,color=gray]{41}}
        \put(\LenToUnit{\@tempdimb},\LenToUnit{\@tempdima}){%
        \pgfornament[anchor=south east,width=0.75in,symmetry=c,color=gray]{41}}
    \endgroup
}
\makeatother

\begin{document}

\mainmatter

\pagestyle{principal}

\chapter{Chapter title}

Some funny line\footnote{Some weird footnote text.}

\newpage

Another line

\end{document}

Here's a preview of what this code is doing (no, it's not hacking the Central Bank of America), and the issue shown in red:

enter image description here

So I need to fix two things:

  1. The ornamentations shouldn't be inside the vertical gray region. They should be inside the margins, while the gray region (left and right pages) are reserved for some book informations and the pages binding.

  2. The ornamentations should be used on all pages, but only for the main matter part of the book. There should be no ornamentations on any of the other pages (front matter and back matter).

So how could I fix both issues?

  • Kinda related: Are you using a fully up to date latex installation? If you are the new format includes new hooks to add stuff to the background. Similar to eso-pic plus the picture package. Meaning you don't need LenToUnit. There also dimexpr so you can do the calculations directly. It should be easy enough to add this to the background hook and then clear your hook after the frontmatter – daleif Oct 28 at 20:20
  • @daleif, I’m using TexLive 2015 (can’t upgrade since I work on a big project and don’t want to mess things). I downloaded and hand installed the latest ornaments package. – Cham Oct 28 at 20:24
  • Then you have my sympathies. I'm not at a pc so cannot help – daleif Oct 28 at 20:25
2

Just shift the ornaments in the same way as you did it for the grey margin box.

\documentclass[11pt,letterpaper,twoside]{book}
\usepackage{graphicx, xcolor, calc}
\usepackage{eso-pic}
\definecolor{colorMarge}{RGB}{242,242,245}
\usepackage[object=vectorian]{pgfornament}
\usepackage{lipsum}

\newlength\mymargin
\setlength\mymargin{0.5in}
\newlength\mysize
\setlength\mysize{1.5in}
\newlength\mysep
\setlength\mysep{6mm}

\newcommand\mybox[2][]{%
  \colorbox{colorMarge}{%
    \rotatebox[origin=l]{90}{%
      \parbox[c][\mymargin][c]{\paperheight}{%
        \centering\color{lightgray}\normalfont #1 #2}}}}

\newcommand\leftornament[1]{%
  \put(\LenToUnit{#1}, \LenToUnit{\mysep}){%
    \pgfornament[anchor=south, width=\mysize, color=gray, symmetry=h]{41}}%
  \put(\LenToUnit{#1}, \LenToUnit{\paperheight-\mysep}){%
    \pgfornament[anchor=north, width=\mysize, color=gray]{41}}}

\newcommand\rightornament[1]{%
  \put(\LenToUnit{#1}, \LenToUnit{\mysep}){%
    \pgfornament[anchor=south, width=\mysize, color=gray, symmetry=c]{41}}%
  \put(\LenToUnit{#1}, \LenToUnit{\paperheight-\mysep}){%
      \pgfornament[anchor=north, width=\mysize, color=gray,  symmetry=v]{41}}}

\newcommand\allOrnaments{%
  \setlength\fboxsep{0pt}%
  \ifodd\value{page}%
    \put(0,0){\mybox[\scshape\large]{Name and Year}}%
    \leftornament{\mymargin+\mysep}%
    \rightornament{\paperwidth-\mysize-\mysep}%
  \else
    \put(\LenToUnit{\paperwidth-\mymargin},0){\mybox[\scshape\huge]{Book Title}}%
    \leftornament{\mysep}%
    \rightornament{\paperwidth-\mysize-\mymargin-\mysep}%
  \fi
}

\newcommand\startOrnaments{\AddToShipoutPicture{\allOrnaments}}
\newcommand\stopOrnaments{\ClearShipoutPicture}

\begin{document}
\frontmatter
\chapter{Preface}
\lipsum[1-5]
\mainmatter
\startOrnaments
\chapter{Lorem ipsum}
\lipsum[1-20]
\backmatter
\stopOrnaments
\chapter{The End}
\lipsum[1-5]
\end{document}

enter image description here

| improve this answer | |

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.