0

I'm experiencing a glitch with a decoration command, which moves a bit the text on the page. Here's a stripped down version of the code I'm trying to fix:

\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}
\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 ornementations to corners :
\usepackage[object=vectorian]{pgfornament}

\newcommand*{\pageornament}[2]{
\begin{tikzpicture}[remember picture,overlay]
\color{#2}%
    \node[anchor=north west,xshift=0.5in+2mm,yshift=-2mm] at (current page.north west){% 
    \pgfornament[width=2cm]{#1}};
    \node[anchor=north east,xshift=-2mm,yshift=-2mm] at (current page.north east){%
    \pgfornament[width=2cm,symmetry=v]{#1}};
    \node[anchor=south west,xshift=0.5in+2mm,yshift=2mm] at (current page.south west){% 
    \pgfornament[width=2cm,symmetry=h]{#1}};
    \node[anchor=south east,xshift=-2mm,yshift=2mm] at (current page.south east){% 
    \pgfornament[width=2cm,symmetry=c]{#1}};
\end{tikzpicture}
}

\begin{document}

\pagestyle{principal}

\chapter{Chapter title}

\pageornament{41}{gray}

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

\newpage

Another line

\end{document}

Here's a preview of what this code is doing (we need two compilations to see the result) :

enter image description here

If you desactivate the decoration command \pageornament{41}{gray} (just after the chapter's title), the text moves back to its proper position. Why is the ornament command moving the block of text? How can I prevent this to happen?

6
  • I suggest using eso-pic to place the ornament.
    – Symbol 1
    Oct 28, 2020 at 22:51
  • This is the normal indentation at the beginning of a paragraph. Note that the first paragraph of a section/chapter is not indented. Oct 28, 2020 at 22:53
  • @Andreas Matthias, the command change also the vertical position of the text. I don’t want this to happen. How can I change the command to prevent the text Motion ?
    – Cham
    Oct 28, 2020 at 22:56
  • @Symbol, how? Could you suggest a macro to do the same decoration ?
    – Cham
    Oct 28, 2020 at 22:58
  • 1
    @Cham: Your first paragraph is more or less empty, but nevertheless it is a complete paragraph. Actually it contains two spaces from your macro where you did not comment all newline characters. Your ornament is put into a box, and even if the dimensions of your box would be 0pt x 0pt it would still be a box, ie a complete paragaph. And the second paragaph is shifted down. -- Don't go this way. Try it with eso-pic. Oct 28, 2020 at 23:21

1 Answer 1

1

Use the \AddToHook macro to extend the \shipout macro to output the contents of a zero-sized picture, at the top left (0,0) of the page.

% pagedecoprob.tex  Try for decorative page margins

\documentclass{book} \usepackage{geometry}  %%%% SE 568730  or
%\documentclass{memoir}  %%%% SE 568730

\usepackage{comment}
\usepackage{lipsum}

\begin{document}

% seems like picture can now cope with actual values
% inset from page edges, change this to suit
\newlength{\linset} \setlength{\linset}{\baselineskip} 
% x coordinate of RHS 
\newlength{\rloc} \setlength{\rloc}{\paperwidth} \addtolength{\rloc}{-\linset}
% (-) y coordinate of bottom location
\newlength{\bloc} \setlength{\bloc}{\paperheight} \addtolength{\bloc}{-\linset}

% the decorative elements and their placements
\newcommand{\corners}{% 
  \put(\linset,-\linset){\makebox(0,0)[tl]{linset, -linset}}  % top left
  \put(\rloc,-\linset){\makebox(0,0)[tr]{rloc, -linset}}      % top right
  \put(\linset,-\bloc){\makebox(0,0)[bl]{linset, -bloc}}      % bottom left
  \put(\rloc,-\bloc){\makebox(0,0)[br]{rloc, -bloc}}          % bottom right
}

% use LaTeX arrows as the decorative elements
\renewcommand{\corners}{%
  \put(\linset,-\linset){\makebox(0,0)[tl]{\Huge$\nearrow$}}  % top left
  \put(\rloc,-\linset){\makebox(0,0)[tr]{\Huge$\nwarrow$}}    % top right
  \put(\linset,-\bloc){\makebox(0,0)[bl]{\Huge$\searrow$}}    % bottom left
  \put(\rloc,-\bloc){\makebox(0,0)[br]{\Huge$\swarrow$}}      % bottom right
}

% put decorative elements on this and future pages 
\AddToHook{shipout/background}[mypic]{\corners}

\chapter{First}
\textbf{Added To Hook}
\lipsum[1-12]

\textbf{Removed from Hook}

\RemoveFromHook{shipout/background}[mypic]

\lipsum[1-10]

\textbf{Added to Hook}

\AddToHook{shipout/background}[mypic]{\corners}

\lipsum[1-10]
  
\end{document}

With thanks to @ulrikefischer for showing me the \...Hook code (answer to How do I put (or not) something on every page independently of headers and footers?).

enter image description here

You must log in to answer this question.

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