TransWikia.com

Ornaments command move text

TeX - LaTeX Asked on April 25, 2021

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][][itshapesmallMakeUppercase{chaptername thechapter. chaptertitle}]{itshapesmallMakeUppercase{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 linefootnote{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?

One Answer

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

Answered by Peter Wilson on April 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP