是否可以將名稱新增至邊緣引號?

是否可以將名稱新增至邊緣引號?

以下 MWE 按預期工作:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{quotes}

\begin{document}
\begin{tikzpicture}
  \path (0,0) edge node[auto] (label) {label} (1,1);
  \draw (label.south west) rectangle (label.north east);
\end{tikzpicture}
\end{document}

在此輸入影像描述

但是,當我嘗試替換程式碼行時

\path (0,0) edge node[auto] (label) {label} (1,1);;

\path (0,0) edge ["label",name=label] (1,1);

我收到錯誤“沒有名為 fr0 的形狀未知”...

我預計,根據 TikZ 手冊(第 237 頁)中的描述,應該可以在引號中添加名稱:

具體來說,當載入quotes庫時,每次傳遞給edge或to path命令的選項列表中的鍵值對都以「開頭,鍵值對實際上必須是以下形式的字串:

"<text>"’<options>

該字串被轉換為以下形式:

edge node=node [every edge quotes]<options>]{<text>}

問題:

  • 是否可以向邊緣引用添加一個名稱,稍後可以將其用作座標,如上圖所示?
  • 如果可能的話,該怎麼做?

答案1

您的程式碼不遵循指定的語法。

使用一個更簡單的範例:

\documentclass[tikz]{standalone}
\usetikzlibrary{quotes}
\begin{document}
\begin{tikzpicture}
  \path (0,0) edge ["My name is Harry."{name=Harry}] (1,1);
  \draw (Harry.south west) rectangle (Harry.north east);
\end{tikzpicture}
\end{document}

哈利

當你說

<options>, "<text>"

<options>適用於edge而非edge quotes。你必須使用

"<text>"<options>

正如手冊所說,如果您想<options>應用於edge quotes而不是edge.

比較

  \path (0,0) edge [blue, "My name is Harry."{name=Harry, red}] (1,1);

紅哈利

這適用redMy name is Harry.blueedge當然,這種差異通常是無關緊要的,因為路徑上的節點繼承了這些路徑的屬性。所以如果你只是說

  \path (0,0) edge [blue, "My name is Harry."{name=Harry}] (1,1);

兩者都是Harry並且edge將會是blue

藍色哈利

但這並不是因為blue直接適用於Harry而只是因為路徑上的節點預設從這些路徑繼承顏色。然而,名稱並不是這樣繼承的。因此,如果你想姓名 Harry而不是染色他,你必須使用手冊中指定的語法。

相關內容