2

I'm trying to layout two pages such that the second is a mirror image of the first.

Looking at the previous answers on the subject here, I think I should be able to simply xscale=-1 the second page, having put the tikz commands in a \newcommand, but it seems not to be working for me. Is this maybe because I'm using current page coordinates?

How might I fix this, please?

\documentclass[a4paper,tikz]{article} 

\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{math} 

\begin{document}
    
    \pagestyle{empty}

    \newcommand{\wholepage}{
        \draw (current page.north east) -- (current page.south west);
    }

    \begin{tikzpicture}[remember picture,overlay]
        \wholepage
    \end{tikzpicture}

    \newpage

    \begin{tikzpicture}[remember picture,overlay, xscale=-1]
        \wholepage
    \end{tikzpicture}
        

\end{document}
3
  • You are right in your supposition: the current page coordinates aren't affected by the xscale. Could you add a little more detail about what you are trying to achieve? It feels like you've simplified it a little bit too far for the question. Commented Apr 3, 2022 at 18:33
  • @AndrewStacey The pages are to be printed duplex. The back side of the page needs to be a mirror image of the front. The front is built by a bunch of tikz commands and I'd rather not have to recode them all for the mirrored coordinate system, should there exist an alternative.
    – Ian
    Commented Apr 3, 2022 at 18:39
  • There are other options than redoing the tikz commands. pgfmorepages could handle this by putting a mirrored copy of the page, or if it is a single tikzpicture environment then save it in a box and mirror the entire box. Commented Apr 3, 2022 at 19:09

4 Answers 4

2

Here's a pgfmorepages solution. It defines a new layout, 1 on 2, 2nd mirrored which repeats each page on a second page but mirrored. This will work with anything on the page, whether it uses TikZ or not. Underneath, each page is saved into a box which can then be manipulated before it is actually put on a page. pgf(more)pages allows one to define layouts that do those various manipulations.

\documentclass{article}
%\url{https://tex.stackexchange.com/q/639519/86}
\usepackage{pgfmorepages}
\usepackage{lipsum}

\pgfpagesdeclarelayout{1 on 2, 2nd mirrored}
{
  \edef\pgfpageoptionheight{\the\paperheight}
  \edef\pgfpageoptionwidth{\the\paperwidth}
  \def\pgfpageoptionborder{0pt}
  \def\pgfpageoptionbordercode{}
  \def\pgfpageoptionfirstshipout{1}
}
{
\pgfpagesphysicalpageoptions
  {%
    logical pages=1,%
    physical pages=2,%
    physical height=\pgfpageoptionheight,%
    physical width=\pgfpageoptionwidth,%
    current logical shipout=\pgfpageoptionfirstshipout%
  }
  \pgfpagessetdefaults{%
    border code=\pgfpageoptionbordercode
  }
  \pgfpagesphysicalpage{1}{}
    \pgfpageslogicalpageoptions{1}
    {%
      border shrink=\pgfpageoptionborder,%
      center=\pgfpoint{.5\pgfphysicalwidth}{.5\pgfphysicalheight}%
    }%
  \pgfpagesphysicalpage{2}{}
    \pgfpageslogicalpageoptions{1}
    {%
      border shrink=\pgfpageoptionborder,%
      xscale=-1,%
      % If the above produces a spurious `1` in the middle of the page, use the two lines below instead
%      rotation=180,%
%      yscale=-1,%
      center=\pgfpoint{.5\pgfphysicalwidth}{.5\pgfphysicalheight}%
    }%
}

\pgfpagesuselayout{1 on 2, 2nd mirrored}

\begin{document}

\lipsum

\newpage

\lipsum

\end{document}

The lipsum package is included just to generate some text. When I tried it on one system (MikTeX) then the xscale version produced a spurious 1 somewhere on the page. This didn't happen with my TeXLive distribution, so I'm guessing that my TikZ/PGF installation on the MikTeX system wasn't up to date. Anyway, if you find a spurious 1 in the middle of the page when using xscale then remove that line and uncomment the lines yscale and rotation. Or update your TikZ installation.

each page is repeated and mirrored

2
  • Many thanks Andrew, I tested this last night and it works great. I'll have to check out the documentation for pgfmorepages though to understand it! My printer's duplexer appears to be a tad petulant and doesn't /quite/ align the pages for the second pass identically which, in the spirit of William Morris, I would like to fix. Is there a simple way to add an x,y translate for page 2?
    – Ian
    Commented Apr 7, 2022 at 5:50
  • @Ian I haven't tested it, but I'm almost certain that you can add an offset in the parameters of the center key on the second page. If, say, it needs to be 4mm to the right then it would be .5\pgfphysicalwidth+4mm. Commented Apr 7, 2022 at 5:56
2

I propose to have two separates commands for the two pages (avoid one command with xscale=-1):

\documentclass[a4paper]{article} 
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{math} 
\pagestyle{empty}
\begin{document}
    \newcommand{\wholedown}{%
        \draw[cyan!30,line width=3pt](current page.north west) -- (current page.south east);
    }
    \newcommand{\wholeup}{%
        \draw[cyan!30,line width=3pt](current page.south west)--(current page.north east);
    }
    \begin{tikzpicture}[remember picture,overlay]
        \wholeup
    \end{tikzpicture}
    \newpage
    \begin{tikzpicture}[remember picture,overlay]
        \wholedown
    \end{tikzpicture}
\end{document}

Output:

enter image description here

If you consider to repeat all this for all the document, you can think to use the background package for odd and even pages.

1

This answer is based on these two:

This MWE uses the package eso-pic to create a background image through tikz and xscale. The syntax xscale={2*Mod(\thepage,2)-1} result in -1 and +1 for even and odd pages. Mod is the modulo operation: https://en.wikipedia.org/wiki/Modulo_operation.

Package background still is another option to be considered.

\documentclass[11pt]{article} 
\usepackage{fullpage, lipsum, tikz}
\usepackage{eso-pic}
\usetikzlibrary{calc}
\AddToShipoutPictureBG{%
  \begin{tikzpicture}[remember picture, overlay]
    \node[opacity=.5, inner sep=0pt, xscale={2*Mod(\thepage,2)-1}] 
      at(current page.center)
      {\includegraphics[width=14cm, angle=45]{example-image-duck}}; %*(\thepage-1)
  \end{tikzpicture}%
}
\begin{document}
\lipsum[1-20]
\end{document}

enter image description here

0

This is a solution using background and tikz.

The following MWE presents the crossed lines on even and odd pages. The \includegraphics is just an extra as illustration of what is flipped and what is not. The first tikzpicture draws the borders, which may be removed. The second tikzpicture uses \pgfmathparse from this answer to change behavior acoordingly to even and odd pages. Both \path[fill=<color>] are proofs of concept derived from the linked answer. The command \draw draws the crossed blue lines. I used (+/-<measure>,+/-<measure>) as a lazy shortcut to display the lines at the same coordinate of the borders. Those points may be replaced for other commands.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{graphicx}
\usepackage{lipsum}

\usepackage[pages=all]{background}
\backgroundsetup{
  scale=1,
  color=black,
  opacity=0.4,
  angle=0,
  position = current page.south west,
  nodeanchor = south west,
  hshift = 1.5cm, % horizontal margin
  vshift = 1.5cm, % vertical margin
  contents={%
    \includegraphics[
    height=\dimexpr\paperheight-3cm\relax, % double the vert. margin
    width=\dimexpr\paperwidth-3cm\relax    % double the horiz. margin
    ]{example-image-duck}
    \begin{tikzpicture}[overlay,remember picture]
      \draw [opacity=1,line width=2pt]
      ($ (current page.north west) + (1.5cm,-1.5cm) $)
      rectangle
      ($ (current page.south east) + (-1.5cm,1.5cm) $);
    \end{tikzpicture}
    \begin{tikzpicture}[overlay,remember picture, blue]
      \pgfmathparse{int(Mod(\thepage,2))}
      \let\r\pgfmathresult
      \ifnum\r=1
        \path[fill=red] (current page.north west) circle (1cm);
        \draw [opacity=1,line width=2pt]
        ($ (current page.north west) + (1.5cm,-1.5cm) $)
        --
        ($ (current page.south east) + (-1.5cm,1.5cm) $);
      \else
        \path[fill=blue] (current page.south east) circle (1cm);
        \draw [opacity=1,line width=2pt]
        ($ (current page.north east) + (-1.5cm,-1.5cm) $)
        --
        ($ (current page.south west) + (1.5cm,1.5cm) $);
      \fi
    \end{tikzpicture}
  }
}

\begin{document}
\BgThispage
\lipsum[1-20]
\end{document}

enter image description here

You must log in to answer this question.

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