有沒有辦法使用 \tikzset 設定多部分節點的文字?

有沒有辦法使用 \tikzset 設定多部分節點的文字?

為了建立參數化分割節點,我想在節點部分使用參數。

這是我所做的:

\tikzset{threeParts/.style n args={3}{%
    rectangle split,
    rectangle split horizontal, 
    rectangle split parts=3,
    draw,
    whichKeyShouldIuseHere={
     nodepart{one} {#1}
     nodepart{two} {#2}
     nodepart{three} {#3}},
 }}

\begin{tikzpicture}
  \path  node[threeParts={1,2,3}];
\end{tikzpicture}

但這不起作用,而且我找不到用於填充節點大括號的正確金鑰。

答案1

這個答案需要sourceforge上的CVS版本。 (謝謝托比昂

你要找的鑰匙就是node contents鑰匙。
它可以滿足您的特定需求。

你像這樣使用它:

node contents={<content of node>}

\node[node contents=ABC];

請注意,您不應為使用上述構造的節點提供額外的內容說明符。

所以在你的情況下你會發現:

\tikzset{threeParts/.style n args={3}{%
        rectangle split,
        rectangle split horizontal, 
        rectangle split parts=3,
        draw,
        node contents={#1\nodepart{two}#2\nodepart{three}#3}
    }
}

tikzpicture就變成了:

\begin{tikzpicture}
  \path node[threeParts={Part 1}{Part 2}{Part 3}];
\end{tikzpicture}

請注意,您在部件的 3 個參數方面略有錯誤。
如果您想使用逗號,請執行以下操作:

threePartsComma/.style args={#1,#2,#3}{<previous content>}

並使用:

node[threePartsComma={Hell,o and,welcome}];

在這裡,始終在整個參數周圍使用大括號是非常明智的,因為tikz選項是用逗號解析的。

請注意,您不能使用該node[node contents=< >] at (0,0);構造,應在節點的選項中或通過\path (0,0) node[...];.

一張小圖:

在此輸入影像描述

相關內容