透過兩次測量定位節點

透過兩次測量定位節點

以下引用可在 pgf 手冊第 17 章第 5.3 節中找到。 (「此選項」是指透過兩次測量來指定節點的位置。):

此選項的效果如下。首先,(<number or dimension 2>, <number or dimension 1>)使用評估此類座標的正常規則來計算該點,從而產生某個位置。然後,節點移動該點的垂直分量。錨定在南邊。

我提供了手冊中提供的範例。這個例子是否說明了「這個選項」?如何and 3mm改變節點的位置?

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,shapes,positioning}

\begin{document}

\begin{tikzpicture}
\draw [help lines] (0,0) grid (2,2);
\node at (1,1) [above=0.2 and 3mm, draw] {over};
\end{tikzpicture}

\end{document}

有人想提供一個更好的說明例子嗎?

答案1

above right除非添加,above leftbelow right, below left,否則該選項不起作用。另外,如果你忽略了這一點,你會得到不同的結果and 3mm。比較以下內容:

  • [above right=0.2, draw]

    在此輸入影像描述

  • [above right=0.2 and 3mm, draw]

    在此輸入影像描述

如引文中所解釋的,錨點設置在節點的南邊。錨點就是被「移動」的東西。當然,其餘形狀如下。如果你不知道錨點是什麼,請查看第 49 節“形狀”Tikz-Pgf 手冊(第 477 頁)。如果您願意,可以透過新增鍵anchor=northanchor=north west在選項中設定不同的錨點。

圓的工作方式相同,只不過錨點設置在圓的中心,而不是南邊。如果將範例變更為 has \node at (1,1) [circle, draw] {over};,您會看到它位於精確的中心,但如果添加anchor=south,它將向上移動,使其南邊與網格中心相符。

答案2

我認為有必要進行更多澄清。首先為什麼沒有語法錯誤。那是因為它節省了大量 if then 語法。以古老的風格查看這些選項的內部程式碼\tikzoption(相當於\tikzset

\tikzoption{above}[]{\def\tikz@anchor{south}\tikz@possibly@transform{y}{}{#1}}
\tikzoption{below}[]{\def\tikz@anchor{north}\tikz@possibly@transform{y}{-}{#1}}
\tikzoption{above left}[]%
  {\def\tikz@anchor{south east}%
    \tikz@possibly@transform{x}{-}{#1}\tikz@possibly@transform{y}{}{#1}}

現在,您不需要知道它可能會進行什麼變換等。

您也可以看到相反的錨定效果:您選擇一個選項,它會選擇相反的羅盤方向進行錨定。如果你想覆蓋它,你必須anchor=<foo>在你的選項中添加顯式的。

透過啟用更精細的網格,您實際上可以更好地看到定位

%\usetikzlibrary{positioning}
\begin{tikzpicture}
\draw [help lines] (0,0) grid[step=1mm] (2,2) node at (1,1) {o};
\node at (1,1) [circle,above=0.2 and 3mm, draw] {over};
\end{tikzpicture}

在此輸入影像描述

並且透過右上方您可以獲得準確的移位量

%\usetikzlibrary{positioning,shapes.geometric}
\begin{tikzpicture}
\draw [help lines] (0,0) grid[step=1mm] (2,2) node at (1,1) {o};
\node at (1,1) [ellipse,above right=0.2 and 3mm, draw] {over};
\fill[red] (1,1) ++(3mm,2mm) circle(0.5pt);
\end{tikzpicture}

在此輸入影像描述

相關內容