3

For aligning the notes in a beamer presentation (using PGFPages to put the notes page directly next to the presentation slides) at the same vertical position where the text was outputted, I use pdfsavepos. This works very well unless I need to put the presentation text in a \scalebox. The notes do not follow the scaling - at least not in the way they should.

\documentclass{article}
\usepackage{zref-user, zref-savepos, calc, xcolor, graphicx, lipsum}
\usepackage[absolute]{textpos}
\usepackage[left=1in, top=1in, right=1in, bottom=1in]{geometry}
\begin{document}
   \scalebox{1}{%
      \begin{minipage}{1\textwidth}%
         \lipsum[1]\hrule%
         \zsaveposy{pos}%
         \zrefused{pos}%
         \lipsum[2-6]%
      \end{minipage}%
   }%
   \makeatletter%
   \zref@ifrefundefined{pos}{}{%
      \begin{textblock*}{10cm}(0cm, \dimexpr\paperheight - \zposy{pos}sp)
         \color{red} This should be aligned at the line.%
      \end{textblock*}
   }%
\end{document}

Running the MWE twice with PDFLaTeX, the red text should be right below the line. Now change the scaling factor to .5 and the minipage width to 2\textwidth. The position of the red text seems to follow the scaling, but far too much, not being aligned right after the line. Note the effect gets worse the longer the \lipsum after the reference point is. How can I compensate for this shift?

(In the actual presentation, I use a technique different from textpos, but the behaviour is exactly the same.)

3

From the point of view of pdftex the scaling actually doesn't change the size of the content. LaTeX manipulates the outer size of the box (the height,depth and width) so that is doesn't take up to much place on the page, but the inner linewidth, the font size etc don't change. That means that the content "spills" out of the box and the zref-markers reflect the natural size of the box (normally) a bit moved up (as the height of the box is smaller). The "real" scaling is done with a pdf literal, the pdf viewer does all the work to show a smaller box and smaller font.

So for LaTeX (and zref) the page looks like this (as the minipage has its baseline in the middle):

 \documentclass{article}
\usepackage[left=1in, top=1in, right=1in, bottom=1in]{geometry}
\usepackage{lipsum,xcolor}
\fboxrule=1pt
\begin{document}
 \vspace*{5cm}%to show the full box:
 \parindent0pt
 \fcolorbox{black}{green!10!white}{\makebox[0.5\width][l]{%
       \raisebox{0pt}[0.5\height][0.5\depth]
       {
        \begin{minipage}{1\textwidth}%
         \lipsum[1]\hrule%
         \lipsum[1]%
        \end{minipage}%
       }}}%
\end{document}    

enter image description here

And this is where zref places the markers:

\documentclass{article}
\usepackage{zref-user, zref-savepos, calc, xcolor, graphicx, lipsum}
\usepackage[absolute]{textpos}
\usepackage[left=1in, top=1in, right=1in, bottom=1in]{geometry}

\begin{document}
\vspace*{5cm} %to show the full box:
\parindent=0pt%
   \scalebox{0.5}{%
      \begin{minipage}{1\textwidth}%
         \zsavepos{postop}x\hfill y\zsavepos{postopright}\par
         \lipsum[1]\hrule%
         \zsavepos{posmid}%
         \lipsum[1]%
         \zsavepos{posbot}
      \end{minipage}%
   }%
      \begin{textblock*}{10cm}(\zposx{postopright}sp, \dimexpr\paperheight - \zposy{postopright}sp)
         \color{red}top right%
      \end{textblock*}
      \begin{textblock*}{10cm}(\zposx{postop}sp, \dimexpr\paperheight - \zposy{postop}sp)
         \color{red}top%
      \end{textblock*}
      \begin{textblock*}{10cm}(\zposx{posmid}sp, \dimexpr\paperheight - \zposy{posmid}sp)
         \color{blue}middle%
      \end{textblock*}
      \begin{textblock*}{10cm}(\zposx{posbot}sp, \dimexpr\paperheight - \zposy{posbot}sp)
         \color{green}bottom%
      \end{textblock*}
\end{document}

enter image description here

This means that if you really want to use zrefpos along with scaling (or other manipulation of this type) you will have to calculate the correct values.

1

Ok, I have managed to do the calculation in a very general way. Comments are appreciated, as the current solution works, but can be made much prettier. I have basically redefined the \zsavepos-macros so that they do the calculation internally. But for this, I had to use another label (i.e. two runs are now required), as I did not manage to get the value of \pdflast(x|y)pos even if I put the macro in a \AtBeginShipout environment.

\documentclass{article}
\usepackage{zref-user, zref-savepos, calc, xcolor, adjustbox, lipsum}
\usepackage[absolute]{textpos}
\usepackage[left=1in, top=1in, right=1in, bottom=1in]{geometry}

\makeatletter

\newcounter{@scaleposes}
\newlength\@scaleposiny%
\newlength\@scaleposinx%
\def\@patchposes#1#2{%
   \renewcommand{\zsavepos}[1]{%
      \pdfsavepos%
      \protected@write\@auxout{}{%
         \string\zref@newlabel{##1@orig}{%
            \ltx@backslashchar posx{\noexpand\the\pdflastxpos}%
            \ltx@backslashchar posy{\noexpand\the\pdflastypos}%
         }%
      }
      \zifrefundefined{##1@orig}{}{%
         \edef\@posxBox{\zref@extract{#1}{posx}}%
         \edef\@posxCnt{\zref@extract{##1@orig}{posx}}%
         \setlength\@scaleposinx{\@posxBox sp - \@posxCnt sp}%
         \setlength\@scaleposinx{#2\@scaleposinx}%
         \setlength\@scaleposinx{\@posxBox sp - \@scaleposinx}%
         \edef\@posyBox{\zref@extract{#1}{posy}}%
         \edef\@posyCnt{\zref@extract{##1@orig}{posy}}%
         \setlength\@scaleposiny{\@posyBox sp - \@posyCnt sp}%
         \setlength\@scaleposiny{#2\@scaleposiny}%
         \setlength\@scaleposiny{\@posyBox sp - \@scaleposiny}%
         \protected@write\@auxout{}{\string\zref@newlabel{##1}%
            {\ltx@backslashchar posx\expandafter{\number\@scaleposinx}%
             \ltx@backslashchar posy\expandafter{\number\@scaleposiny}}}%
      }%
   }%
   \renewcommand{\zsaveposx}[1]{%
      \pdfsavepos%
      \protected@write\@auxout{}{%
         \string\zref@newlabel{##1@orig}{\ltx@backslashchar posx{\noexpand\the\pdflastxpos}}%
      }
      \zifrefundefined{##1@orig}{}{%
         \edef\@posxBox{\zref@extract{#1}{posx}}%
         \edef\@posxCnt{\zref@extract{##1@orig}{posx}}%
         \setlength\@scaleposinx{\@posxBox sp - \@posxCnt sp}%
         \setlength\@scaleposinx{#2\@scaleposinx}%
         \setlength\@scaleposinx{\@posxBox sp - \@scaleposinx}%
         \protected@write\@auxout{}{\string\zref@newlabel{##1}%
            {\ltx@backslashchar posx\expandafter{\number\@scaleposinx}}}%
      }%
   }%
   \renewcommand{\zsaveposy}[1]{%
      \pdfsavepos%
      \protected@write\@auxout{}{%
         \string\zref@newlabel{##1@orig}{\ltx@backslashchar posy{\noexpand\the\pdflastypos}}%
      }
      \zifrefundefined{##1@orig}{}{%
         \edef\@posyBox{\zref@extract{#1}{posy}}%
         \edef\@posyCnt{\zref@extract{##1@orig}{posy}}%
         \setlength\@scaleposiny{\@posyBox sp - \@posyCnt sp}%
         \setlength\@scaleposiny{#2\@scaleposiny}%
         \setlength\@scaleposiny{\@posyBox sp - \@scaleposiny}%
         \protected@write\@auxout{}{\string\zref@newlabel{##1}%
            {\ltx@backslashchar posy\expandafter{\number\@scaleposiny}}}%
      }%
   }%
}
\newenvironment{scalepos}[1]{%
   \begingroup%
      \stepcounter{@scaleposes}%
      \edef\@spn{scaleposes-\the\value{@scaleposes}}%
      \zsavepos{\@spn}%
      \zrefused{\@spn}%
      \expandafter\@patchposes\expandafter{\@spn}{#1}
      \begin{adjustbox}{scale=#1}%
}{
      \end{adjustbox}%
   \endgroup%
}


\begin{document}
   \begin{scalepos}{.7}%
      \begin{minipage}[t]{1.43\textwidth}
         \zsavepos{postA}\zrefused{postA}%
         \lipsum[1-6]
         \hfill Right end
         \zsavepos{posbA}\zrefused{posbA}%
      \end{minipage}
   \end{scalepos}%
   \zref@ifrefundefined{postA}{}{%
      \begin{textblock*}{10cm}(\zposx{postA}sp, \dimexpr\paperheight - \zposy{postA}sp)
         \noindent\color{red} Top%
      \end{textblock*}
      \begin{textblock*}{10cm}(\zposx{posbA}sp, \dimexpr\paperheight - \zposy{posbA}sp)
         \noindent\color{red} Bottom
      \end{textblock*}
   }%
\end{document}

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.