5

Question

How can I readjust TikZ's dimension variables to fit a mid-document dimension change as in this example and using the TikZ drawing from here.

Problem

TikZ coordinates are not where they should be. See this example for the correct coordinate alignment on the page.

Criteria

Just to clarify:

  • Page dimensions must be exactly height=224mm by width=130mm (tray dimensions)
  • Origin of disk must be exactly -119.98mm below the top of the page (current page.north)

Procedure

I set my custom lengths for the DVD tray:

\newlength{\pagewidthDVDTray}
\newlength{\pageheightDVDTray}
\setlength{\pagewidthDVDTray}{130mm}
\setlength{\pageheightDVDTray}{224mm}

I created a command that creates a new geometry for the geometry package:

\newcommand{\generatePageLayouts}{%
  \newgeometry{layoutwidth=\pagewidthDVDTray,layoutheight=\pageheightDVDTray,left=0mm,right=0mm,bottom=0mm,top=0mm}
  \savegeometry{LayoutPageDVDTray}
}%

I created a command that switches to the new layout:

\newcommand{\switchToLayoutDVDTray}{%
  \pdfpagewidth=\pagewidthDVDTray \pdfpageheight=\pageheightDVDTray % for PDF output
  \paperwidth=\pagewidthDVDTray \paperheight=\pageheightDVDTray     % for TikZ
  \loadgeometry{LayoutPageDVDTray} % note; \loadgeometry may reset paperwidth/h!
}

I loaded the commands immediately after \begin{document}

\generatePageLayouts
\switchToLayoutDVDTray

Situation

I have a shared preamble that must have certain dimesions specified like the following:

\usepackage[%
     a4paper,
     head=1.5cm,%\baselineskip,  % distance from bottom of header to block of text aka \headsep e.g. \baselineskip
     foot=1.5cm,  % distance from top of footer to block of text aka \footskip
     headheight=12pt,     % height for the header block (no equivalent for footer)
     marginparwidth=2cm,  % right marginal note width
     marginparsep=2mm,    % distance from text block to marginal note box
     top=2.5cm,           % distance of the text block from the top of the page
     bottom=3cm,
     left=2.5cm,
     right=2.5cm,
 ]{geometry}

One of my documents needs to use many variables from the preamble, but has a different paper size. Changing the page dimensions for TikZ is proving to be difficult.

Example Code

\documentclass[10pt]{article}
\usepackage[quiet]{fontspec}
\usepackage[%
     a4paper,
     head=1.5cm,%\baselineskip,  % distance from bottom of header to block of text aka \headsep e.g. \baselineskip
     foot=1.5cm,  % distance from top of footer to block of text aka \footskip
     headheight=12pt,     % height for the header block (no equivalent for footer)
     marginparwidth=2cm,  % right marginal note width
     marginparsep=2mm,    % distance from text block to marginal note box
     top=2.5cm,           % distance of the text block from the top of the page
     bottom=3cm,
     left=2.5cm,
     right=2.5cm,
 ]{geometry}
\newlength{\pagewidthDVDTray}
\newlength{\pageheightDVDTray}
\setlength{\pagewidthDVDTray}{130mm}
\setlength{\pageheightDVDTray}{224mm}
\newcommand{\generatePageLayouts}{%
  \newgeometry{layoutwidth=\pagewidthDVDTray,layoutheight=\pageheightDVDTray,left=0mm,right=0mm,bottom=0mm,top=0mm}
  \savegeometry{LayoutPageDVDTray}
}%
\newcommand{\switchToLayoutDVDTray}{%
  \pdfpagewidth=\pagewidthDVDTray \pdfpageheight=\pageheightDVDTray % for PDF output
  \paperwidth=\pagewidthDVDTray \paperheight=\pageheightDVDTray     % for TikZ
  \loadgeometry{LayoutPageDVDTray} % note; \loadgeometry may reset paperwidth/h!
}

\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathmorphing, decorations.text,positioning}
\begin{document}
\generatePageLayouts
\switchToLayoutDVDTray


\begin{tikzpicture}[remember picture, overlay]
    % Page Anchors
    \node [yshift=-119.98mm,inner sep=0,shape=circle,fill=red,draw] (origin) at (current page.north) {};
    \node [inner sep=0] (east anchor) at (origin -| current page.north east) {};
    % a random point of the circle



    \begin{scope}[even odd rule, remember picture,overlay]
        \clip
            (origin) circle (14mm) % Inner circle
            (origin) ++(0:60mm) arc (0:360:60mm);
        \node [shape=circle,draw,color=red,minimum width=120mm] (physicalArea) at (origin) {Node Circle}; % Physical Disk Edge
        \node [shape=circle,draw,color=green,minimum width=119mm] (printableArea) at (origin) {};
        \draw [fill=blue!20] ($ (origin) + (0,-5mm) $) rectangle ++(-46mm,-46mm);
        \node [shape=circle,minimum width=28mm,color=red,draw,thick] (innerRing) at (origin) {};
        \def \myradius {59mm}
        %\draw [blue,thick] ($ (origin) + ({\myradius*cos(0)}, {\myradius*sin(0)}) $) arc (0:360:\myradius) ;
        \path[draw,color=orange,postaction={decorate,decoration={text along path,text={|\tiny|text along path test},text align=center,reverse path}}]
        ($ (origin) + ({\myradius*cos(0)}, {\myradius*sin(0)}) $) arc (0:-180:\myradius);
    \end{scope}

    % Layout Scope
    \begin{scope}[even odd rule, every node/.style={font=\scriptsize}]
        \tikzset{layout lines/.style={->|,dashed,blue}}
        \draw [layout lines] (origin) -- (current page.north) node [pos=.75,left] {Vertical Offset B: 119.98mm};
        \draw [layout lines] (origin) -- (east anchor) node [pos=.5,above] {Horizontal Offset A: 65mm};


        \node [align=center,anchor=north] at ($ (physicalArea.south) + (0,-5mm) $) {%
            {\Large\bfseries Calibration for Disk Tray J on Printer iP7250}\\
            Ensure that the printer is not automatically scaling the output in the advanced tab of the initial print dialog.\\[5mm]
            {\bfseries Physical Disk Tray Dimensions:}\\
            Height = 224 mm\\
            Width = 130 mm\\
            Margins = 0 mm};
            \clip
                (origin) circle (14mm) % Inner circle
                (origin) ++(0:60mm) arc (0:360:60mm);
            \draw [layout lines] (innerRing.west) -- (printableArea.west) node [pos=.5,above] {Printable Area: 45mm};
            \path [draw,red] (origin) ++(145:60mm) node [inner sep=0] (arbitrary145) {};
            \draw [layout lines,pos=.5,above,postaction={decorate,decoration={text along path,reverse path,raise=4pt,text align=center,text={|\scriptsize\color{blue}|Physical Area: 46mm}}}] (origin) -- (arbitrary145) ;
    \end{scope}

\end{tikzpicture}

\end{document}

Output

enter image description here

  • First remark, don't use absolut dimensions like 119.98mm in\node [yshift=-119.98mm,inner sep=0,shape=circle,fill=red,draw] (origin) at (current page.north) {}; try to replace this by some thing \textheight, \paperheight, .8\paperheight – touhami Mar 1 '15 at 13:29
  • No, it is absolutely necessary to use absolute dimensions. It is a finely-tuned document to fit a DVD printing tray. – Jonathan Komar Mar 1 '15 at 13:48
  • did you see my last comment below – touhami Mar 1 '15 at 15:16
  • Where did your solution go? strange. – Jonathan Komar Mar 2 '15 at 10:28
  • I decided to delete it as you choose to ignore it, but irepeat you can uncomment %\savegeometry{LayoutPageDVDTray} and %\loadgeometry{LayoutPageDVDTray} your code will work fine – touhami Mar 2 '15 at 19:44
1
+50

All you need is redefine the two commands like this

\newcommand{\generatePageLayouts}{%
  \newgeometry{layoutwidth=\pagewidthDVDTray,layoutheight=\pageheightDVDTray,left=0mm,right=0mm,bottom=0mm,top=0mm}
  %\savegeometry{LayoutPageDVDTray}
}%
\newcommand{\switchToLayoutDVDTray}{%
  \pdfpagewidth=\pagewidthDVDTray \pdfpageheight=\pageheightDVDTray % for PDF output
  \paperwidth=\pagewidthDVDTray \paperheight=\pageheightDVDTray     % for TikZ
  %\loadgeometry{LayoutPageDVDTray} % note; \loadgeometry may reset paperwidth/h!
}

moreover you don't need

\generatePageLayouts 

at all

Edit: or you can just redefine

\newcommand{\switchToLayoutDVDTray}{%
\loadgeometry{LayoutPageDVDTray} %
\pdfpagewidth=\pagewidthDVDTray \pdfpageheight=\pageheightDVDTray % for PDF output
\paperwidth=\pagewidthDVDTray \paperheight=\pageheightDVDTray     % for TikZ
 }

Why? to change pdfpagewidth and height you need newpage. loadgeometry do this but you had call it later

Edit: more explanation

when we call

\generatePageLayouts

we save a newgeometry that's

layoutwidth=\pagewidthDVDTray,layoutheight=\pageheightDVDTray,left=0mm,right=0mm,bottom=0mm,top=0mm

but we save implicitly the paper size here a4. Next when we call

\switchToLayoutDVDTray

we define new pdfpage size

\pdfpagewidth \pdfpageheight 

and paper size \paperwidth \paperheight but this paper size will be destroyed by

\loadgeometry{LayoutPageDVDTray}

which active the geometry saved so the paper size is a4. Now the pdfpage is correctly=224*130 but the paper size in tikz eyes (as commented in the OP's code) is a4 and the current page.north is in top at 105mm from left and not at 65mm.

  • Could you please explain how current page.center is exactly 119.98mm below current page.north? – Jonathan Komar Mar 1 '15 at 14:26
  • No it is not it is 112mm=224/2 below – touhami Mar 1 '15 at 14:49
  • Ok, that is what I thought. That is exactly why I cannot accept your answer. As I said above, this document is finely-tuned for a specific print on a specific tray. The origin must be exactly 119.98mm below current page.north. – Jonathan Komar Mar 1 '15 at 14:54
  • you can use \setlength{\pageheightDVDTray}{239.96mm} no? – touhami Mar 1 '15 at 14:56
  • can you explain more your need – touhami Mar 1 '15 at 14:57

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.