现在是令人尴尬的提问时间。为什么我的计算坐标全部是否出现在相同位置?较大的实心四分之一圆用以下方式绘制:
current page.\x
其中\x
是south west
,north west
,north east
,south east
,这些都很好用。但是当我计算自己的位置时:
\coordinate (South West) ($(current page.south west) + ( \XMargin, \XMargin)$) ;
\coordinate (North West) ($(current page.north west) + ( \XMargin,-\XMargin)$) ;
\coordinate (North East) ($(current page.north east) + (-\XMargin,-\XMargin)$) ;
\coordinate (South East) ($(current page.south east) + (-\XMargin, \XMargin)$) ;
它们都显示在同一个位置,如同心圆所示:
正确的输出应该是这些同心圆分布在页面周围。
参考:
代码:
\def\PaperWidth{3.0 in}
\def\PaperHeight{2.0 in}
\def\Bleed{0.15 in}
\def\SafetyMargin{0.35 in}
\documentclass{article}
\usepackage[
paperwidth=\PaperWidth,
paperheight=\PaperHeight,
margin=\dimexpr\Bleed+\SafetyMargin\relax,
]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}
\pagestyle{empty}
\usepackage{printlen}\uselengthunit{in}
\newlength{\XMargin}
\begin{document}
\pgfmathsetlength{\XMargin}{\Bleed + \SafetyMargin}
\noindent
\begin{tikzpicture}[overlay, remember picture]
\coordinate (South West) ($(current page.south west) + ( \XMargin, \XMargin)$) ;
\coordinate (North West) ($(current page.north west) + ( \XMargin,-\XMargin)$) ;
\coordinate (North East) ($(current page.north east) + (-\XMargin,-\XMargin)$) ;
\coordinate (South East) ($(current page.south east) + (-\XMargin, \XMargin)$) ;
% Why are these all showing up at the same point???
\foreach [count=\xi] \x/\Color/\InnerSep in {South West/orange/4, North West/brown/5, North East/red/6, South East/blue/7} {
\node [circle, draw=\Color, inner sep=\InnerSep pt] at (\x) {\xi};
}
% This works just fine
\foreach \x/\Color in {south west/orange, north west/brown, north east/red, south east/blue} {
\node [circle, fill=\Color, inner sep=0.25in] at (current page.\x) {};
}
\node at (current page.center) {xmargin is \printlength{\XMargin}};
\end{tikzpicture}
\end{document}
答案1
好吧,正如您已经发现的那样,您at
在坐标规范中遗漏了一个:
\coordinate (South West) at ($(current page.south east) + (-\XMargin, \XMargin)$);
\coordinate (North West) at ($(current page.south west) + ( \XMargin, \XMargin)$);
\coordinate (North East) at ($(current page.north west) + ( \XMargin,-\XMargin)$);
\coordinate (South East) at ($(current page.north east) + (-\XMargin,-\XMargin)$);
答案2
仅回答评论中的问题:
我还想知道为什么涉及坐标的缺失
at
不会触发消息错误。
原因是 是\coordinate (South West) ($(current page.south west) + ( \XMargin, \XMargin)$) ;
一个完全有效的 TikZ 命令。它表示“用(0,0)
标签标记为坐标South West
,然后移动到(complicated point)
。”。 这(0,0)
是因为没有明确的坐标规范,并且坐标尺寸全部设置0
为路径的开头。解释是因为(在没有 的情况下beamer
),\coordinate
扩展为\path coordinate
,因此命令为:
\path coordinate (South West) ($(current page.south west) + ( \XMargin, \XMargin)$) ;
这是完全有效的。当然,它什么也不做(除了弄乱边界框),但它确实意味着你可以这样做:
\coordinate (a) (0,1) [draw] -- (2,0) coordinate (b);
它会从 到 画一条线(0,1)
,(2,0)
并在那里粘贴另一个坐标。不能做的是:
\coordinate[draw] (a) -- (2,0);
有两个原因:路径没有得到它的正式初始移动(坐标在,(0,0)
但路径实际上还没有已移动在那里),并且draw
命令被发送给coordinate
节点,但是它不执行任何操作(因为coordinate
节点没有形状)。
当然,如果您计划做比\coordinate (a) at (38,42);
这更复杂的事情,那么您可能会首先使用\path
(或\draw
或)。因此,如果这样做是为了提高灵活性,那么这可能是不必要的。但事实并非如此,这样做是为了确保行为\fill
\coordinate
\coordinate
确切地这样\path coordinate
您就可以放心地知道,无论您如何指定坐标,它们的结果都是相同的。
一些可供使用的代码:
\documentclass{article}
%\url{http://tex.stackexchange.com/q/79358/86}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (a) (0,1) [draw] -- (2,0) coordinate (b);
\draw (a) to[bend left] (2,0);
\end{tikzpicture}
\end{document}