I need to use the current page.center
position in a memoir
document to center some images on a page. (unless someone has an entirely different suggestion about how to display images like this.)
However, because I am using a trimmed paper size smaller than the stock paper size, TikZ
's current page.center
node doesn't work as intended.
Texample.net has a solution by redefining the current page bounding box to fit memoir's recto/verso and trimmed layout, but I'm struggling to get it to work.
Several problems I don't understand:
It doesn't work on the first page, there must be text and a page break or it'll throw errors
The images display on top of one another (as expected), but when I add a
\clearpage
or a\pagebreak
or a\newpage
or anything else I can think of, it throws errors.
Here's my MWE:
\documentclass[showtrims]{memoir}
\usepackage{tikz}
\usepackage{mwe}
\trimFrame
\setstocksize{11in}{8.5in}
\settrimmedsize{9in}{7in}
\checkandfixthelayout
%%%%%%%%%%%%%%%%%%%%%%%%%%%% Code From Texample.net %%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usetikzlibrary{decorations.pathmorphing}
% Special current page bounding box rectangle that adapts to stock paper sizes
% and recto/verso pages
\newcommand\setpagenode{
% The original current page node code can be found in the file
% generic/pgf/modules/pgfmoduleshapes.code.tex
\expandafter\def\csname pgf@sh@ns@current page\endcsname{rectangle}
% Use a few low level Memoir macros to check if we are on an even or odd page.
\strictpagecheck
\checkoddpage
\ifoddpage%
\expandafter\def\csname pgf@sh@np@current page\endcsname{%
% Set the current page.south west coordinate
\def\southwest{\pgfpoint{\stockwidth-\paperwidth-\trimedge}%
{\stockheight-\trimtop-\paperheight}}%
% Set the current page.north east coordinate
\def\northeast{\pgfpoint{\stockwidth-\trimedge}{\stockheight-\trimtop}}%
}
\else
\expandafter\def\csname pgf@sh@np@current page\endcsname{%
\def\southwest{\pgfpoint{\trimedge}{\stockheight-\trimtop-\paperheight}}%
\def\northeast{\pgfpoint{\trimedge+\paperwidth}{\stockheight-\trimtop}}%
}
\fi
\expandafter\def\csname pgf@sh@nt@current page\endcsname{{1}{0}{0}{1}{0pt}{0pt}}
\expandafter\def\csname pgf@sh@pi@current page\endcsname{pgfpageorigin}
}
% Force recalculation of the current page node whenever the overlay option is used.
% If you page is centered on your stock paper it is only necessary to calculate
% the current page rectangle once.
\pgfkeys{/tikz/overlay/.add code={}{\setpagenode}}
%%%%%%%%%%%%%%%%%%%%%%%%% End Code From Texample.net %%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\CenterTallPhoto}[1]{
\begin{tikzpicture}[remember picture, overlay]
\node at (current page.center){\includegraphics[height=\paperheight]{#1}};
\end{tikzpicture}
}
\newcommand{\CenterWidePhoto}[1]{
\begin{tikzpicture}[remember picture, overlay]
\node at (current page.center){\includegraphics[width=\paperwidth]{#1}};
\end{tikzpicture}
}
\begin{document}
If this text is removed, I get errors.
\pagebreak
\CenterTallPhoto{example-image-10x16}
% \clearpage
\CenterWidePhoto{example-image-16x10}
\end{document}
Errors:
Errors from adding \clearpage
:
./TableQuestion.tex:76: Paragraph ended before \pgfpoint was complete. [ \CenterWidePhoto{example-image-16x10}]
./TableQuestion.tex:76: Missing number, treated as zero. [ \CenterWidePhoto{example-image-16x10}]
./TableQuestion.tex:76: Illegal unit of measure (pt inserted). [ \CenterWidePhoto{example-image-16x10}]
Errors from removing text and page break at the top:
./TableQuestion.tex:74: Paragraph ended before \pgfpoint was complete. [ \CenterTallPhoto{example-image-10x16}]
./TableQuestion.tex:74: Missing number, treated as zero. [ \CenterTallPhoto{example-image-10x16}]
./TableQuestion.tex:74: Illegal unit of measure (pt inserted). [ \CenterTallPhoto{example-image-10x16}]
./TableQuestion.tex:76: Paragraph ended before \pgfpoint was complete. [ \CenterWidePhoto{example-image-16x10}]
./TableQuestion.tex:76: Missing number, treated as zero. [ \CenterWidePhoto{example-image-16x10}]
./TableQuestion.tex:76: Illegal unit of measure (pt inserted). [ \CenterWidePhoto{example-image-16x10}]
I'm typesetting a pretty complicated book, so while I could make a use-case-specific work around for every time I use these page nodes, my code would get really messy and I constantly have little mistakes (miscalculations, spaces) that build up and throw things off. Seems like if I just understood what is going wrong, this should be the "right" solution.
overlay
when you don't (apparently) have any (other) content? This is designed for use when you want to overlay the picture with the main content. But that doesn't seem to be the idea here. (If you want the images to overlap, you might wantoverlay
for one of them. But it seems you don't want that either if you want to clear the page between them?)