问题
我怎样才能重新调整 TikZ 的尺寸变量以适应文档中间的尺寸变化,就像这样例子并使用 TikZ 绘图这里。
问题
TikZ 坐标不在应在的位置。请参阅这个例子以便在页面上正确对齐坐标。
标准
只是为了澄清:
- 页面尺寸必须正好是高度=224mm、宽度=130mm(托盘尺寸)
- 磁盘原点必须精确位于页面顶部以下 -119.98 毫米 (
current page.north
)
程序
我设置了 DVD 托盘的自定义长度:
\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!
}
我立即加载了命令\begin{document}
\generatePageLayouts
\switchToLayoutDVDTray
情况
我有一个共享的序言,它必须具有如下所示的特定尺寸:
\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}
我的一个文档需要使用序言中的许多变量,但纸张大小不同。更改 TikZ 的页面尺寸被证明很困难。
示例代码
\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}
输出
答案1
你只需要像这样重新定义这两个命令
\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!
}
此外你不需要
\generatePageLayouts
根本
编辑:或者你可以重新定义
\newcommand{\switchToLayoutDVDTray}{%
\loadgeometry{LayoutPageDVDTray} %
\pdfpagewidth=\pagewidthDVDTray \pdfpageheight=\pageheightDVDTray % for PDF output
\paperwidth=\pagewidthDVDTray \paperheight=\pageheightDVDTray % for TikZ
}
为什么?要更改 pdfpagewidth 和 height,您需要 newpage。loadgeometry 执行此操作,但您必须稍后调用它
编辑:更多解释
当我们打电话时
\generatePageLayouts
我们保存了一个新的几何图形
layoutwidth=\pagewidthDVDTray,layoutheight=\pageheightDVDTray,left=0mm,right=0mm,bottom=0mm,top=0mm
但我们在这里隐式保存了纸张尺寸 a4。接下来当我们调用
\switchToLayoutDVDTray
我们定义新的 pdfpage 大小
\pdfpagewidth \pdfpageheight
和纸张尺寸 \paperwidth \paperheight 但此纸张尺寸将被破坏
\loadgeometry{LayoutPageDVDTray}
激活已保存的几何图形,因此纸张大小为 a4。现在 pdfpage 正确为 = 224*130,但 tikz 眼中的纸张大小(如 OP 的代码中所述)为 a4,并且当前 page.north 位于顶部,距左侧 105 毫米处,而不是 65 毫米处。