
次の MWE を検討してください。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}
\usetikzlibrary{3d}
\makeatletter
\tikzset{
fitting node/.style={
inner sep=0pt,
fill=none,
draw=none,
reset transform,
fit={(\pgf@pathminx,\pgf@pathminy) (\pgf@pathmaxx,\pgf@pathmaxy)}
},
reset transform/.code={\pgftransformreset},
}
\makeatother
\tikzstyle{dr} = [draw, rectangle, line width=1pt, font=\Huge, align=left]
\tikzstyle{cl} = [>=latex,->,line width=1pt]
\begin{document}
\begin{tikzpicture}[
% x={(0.5cm,0.5cm)}, y={(1cm,0cm)}, z={(0cm,1cm)},
% every node/.append style={transform shape},
]
\draw[very thick] (0,0) rectangle (18,8) node[fitting node] (starter) {};
\begin{scope}[
shift={(1,1)},
% canvas is yx plane at z=0.25,
]
\node[dr] (NodeA) at (1,5) {Node A};
\draw[dr] (4.5,2.5) rectangle (11,6.5) node [fitting node] (NodeB) {Node B\\Slightly bigger};
\node[dr] (NodeC) [above=10pt of NodeB.south, anchor=south] {Node C};
\draw[cl] (NodeA) -- (NodeB);
\draw[cl] (NodeA) |- ($(NodeB.north west)-(10pt,10pt)$) -- ($(NodeB.south west)-(10pt,7.5pt)$) -| ($(NodeC.south west)+(10pt,0)$);
\end{scope}
\end{tikzpicture}
\end{document}
そのままコンパイルすると、ノードと接続線の予想通りの配置が得られます。
しかし、MWE のコメント行のコメントを解除して 3D を有効にすると、次のようになります。
NodeB のテキストが遠近法で表示されていないことは、それほど気になりません。気になるのは、NodeB のフィッティング ノードの長方形に基づく座標が、3D 変換では適切に機能しないことです (「適切な」ノード間ではすべて正常であることに注意してください。たとえば、NodeC に直接入っている線の一部など)。
(特にこの例は、フィッティング ノードの四角形がなくても実行できることはわかっています。そうすれば問題は解決します。問題は、TikzEdt での GUI 編集にこれらが非常に役立つため、至る所にこれらが大量に含まれているコードがあるということです。そのため、代わりに「フィッティング ノード」スタイルを修正するなどの解決策を希望しています。)
答え1
どこに問題があるのか分かりません。ノードtransform shape
に適用されていないのかもしれませんfit
。誰もより良い解決策を提供しない場合、ここに回避策があります。
label={center:{node text}}
ノードのオプションとして使用fitting
:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}
\usetikzlibrary{3d}
\makeatletter
\tikzset{
fitting node/.style={
inner sep=0pt,
fill=none,
draw=none,
reset transform,
fit={(\pgf@pathminx,\pgf@pathminy) (\pgf@pathmaxx,\pgf@pathmaxy)}
},
reset transform/.code={\pgftransformreset},
}
\makeatother
\tikzstyle{dr} = [draw, rectangle, line width=1pt, font=\Huge, align=left]
\tikzstyle{cl} = [>=latex,->,line width=1pt]
\begin{document}
\begin{tikzpicture}[
x={(0.5cm,0.5cm)}, y={(1cm,0cm)}, z={(0cm,1cm)},
every node/.append style={transform shape},
]
\draw[very thick] (0,0) rectangle (18,8) node[fitting node] (starter) {};
\begin{scope}[
shift={(1,1)},
canvas is yx plane at z=0.25,
]
\node[dr] (NodeA) at (1,5) {Node A};
\draw[dr] (4.5,2.5) rectangle (11,6.5) node [fitting node, label={center:{Node B\\Slightly bigger}}] (NodeB) {};
\node[dr] (NodeC) [above=10pt of NodeB.south, anchor=south] {Node C};
\draw[cl] (NodeA) -- (NodeB);
\draw[cl] (NodeA) |- ($(NodeB.north west)-(10pt,10pt)$) -- ($(NodeB.south west)-(10pt,7.5pt)$) -| ($(NodeC.south west)+(10pt,0)$);
\end{scope}
\end{tikzpicture}
\end{document}
答え2
編集: この回答は Texlive 2014 でフリーズしたため壊れていることに注意してください。
わかりました。理解できたと思いますが、現時点ではなぜなのかよくわかりません。
まず、問題は がfit
まさに指示されたとおりに動作することです。つまり、最後の pgf の最小値と最大値の x と y に適合するように指示し、それがまさに実行されます ( を に変更すると確認できますdraw=red
) fitting node
。
問題は、長方形が に到達するまでにすでに変換されているにfit
もかかわらず、fit
3D 変換を認識していないということのようです。
そこで、変換を停止し、長方形フィッティングノードを実行してから、変換を復元しようとしましたが、うまくいきませんでした。pgf 描画コマンドをグループ化し、それらすべてに変換を適用する方法を探しましたが、見つけられませんでした。
そして私は見つけた#47797 (tikz) 長方形パス上にノード アンカーのようなポイントを確立する方法 (説明されている方法よりも優れた方法はありますか)?、そしてそれを使用して、座標アンカーが四角形に追加されるようにしました - そして、とりわけ、fit
四角形のアンカーを試しました...そして突然それが機能しますか??そして、上記の問題に対する私の理論のように、それがどのように座標変換を中断するかわかりません??
ただし、出力は次のようになります。
... 残念ながら、スタイルを変更して先に進むことはできませんfitting node
(四角形とそれに対応するフィッティング ノードへの参照をあらゆる場所に追加する必要があります)。コードは TikzEdt GUI と同じように機能するので、問題ありません。コードは次のとおりです。
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}
\usetikzlibrary{3d}
\makeatletter
%https://tex.stackexchange.com/a/47797/2595
\tikzset{add reference/.style={insert path={%
coordinate [pos=0,xshift=-0.5\pgflinewidth,yshift=-0.5\pgflinewidth] (#1 south west)
coordinate [pos=1,xshift=0.5\pgflinewidth,yshift=0.5\pgflinewidth] (#1 north east)
coordinate [pos=.5] (#1 center)
(#1 south west |- #1 north east) coordinate (#1 north west)
(#1 center |- #1 north east) coordinate (#1 north)
(#1 center |- #1 south west) coordinate (#1 south)
(#1 south west -| #1 north east) coordinate (#1 south east)
(#1 center -| #1 south west) coordinate (#1 west)
(#1 center -| #1 north east) coordinate (#1 east)
}}}
\tikzset{
fitting node/.style={
inner sep=0pt,
fill=none,
draw=red,
fit={(#1 south west) (#1 north east)},
},
}
\makeatother
\tikzstyle{dr} = [draw, rectangle, line width=1pt, font=\Huge, align=left]
\tikzstyle{cl} = [>=latex,->,line width=1pt]
\begin{tikzpicture}[
x={(0.5cm,0.5cm)}, y={(1cm,0cm)}, z={(0cm,1cm)},
every node/.append style={transform shape},
]
\draw[very thick] (0,0) rectangle (18,8) [add reference=R1] node[fitting node=R1] (starter) {};
\begin{scope}[
shift={(1,1)},
canvas is yx plane at z=0.25,
]
\node[dr] (NodeA) at (1,5) {Node A};
\draw[dr] (4.5,2.5) rectangle (11,6.5) [add reference=R2] node [fitting node=R2] (NodeB) {Node B\\Slightly bigger};
\node[dr] (NodeC) [above=10pt of NodeB.south, anchor=south] {Node C};
\draw[cl] (NodeA) -- (NodeB);
\draw[cl] (NodeA) |- ($(NodeB.north west)-(10pt,10pt)$) -- ($(NodeB.south west)-(10pt,7.5pt)$) -| ($(NodeC.south west)+(10pt,0)$);
\end{scope}
\end{tikzpicture}