Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Consider the following 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}

If I compile it as it is, I get the expected arrangement of nodes and connecting lines:

test41.png

But if I enable 3D by uncommenting the commented lines in the MWE, I get this:

test42.png

The NodeB text not being in perspective doesn't bother me all that much; what bothers me is that coordinates based on the NodeB fitting node rectangle do not work properly under 3D transformations (note that all is OK between "proper" nodes, e.g. the piece of the line going right into NodeC).

(I'm aware that this example, in particular, can be otherwise done without the fitting node rectangle - and so problem solved; the thing is, those are quite useful for GUI editing in TikzEdt, and so I have code with a ton of these all over the place; which is why I'd rather have a solution like a fix to the "fitting node" style instead. )

share|improve this question
    
Related: tex.stackexchange.com/questions/47704/… –  sdaau Mar 26 at 19:09
add comment

2 Answers 2

I don't know where is the problem, may be transform shape is not applied to fit nodes. Here you have a workaround if nobody provides a better solution.

Use label={center:{node text}} as option for fitting nodes:

\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}

enter image description here

share|improve this answer
    
Many thanks for that @Ignasi - that fixes the text, but doesn't fix the lines. I'm poking around with this also, and it seems the problem is \pgftransformreset; I'm getting somewhere with \pgfgettransformentries{\ga}{\gb}{\gc}{\gd}{\gsx}{\gsy}\pgfsettransformentries{‌​\ga}{\gb}{\gc}{\gd}{-10pt}{\gsx} instead of it, but my matrix math is a bit rusty, not sure I'll be able to bruteforce my way to a solution. Thanks again - cheers! –  sdaau Mar 26 at 17:02
add comment

Ok, I think I got it, but don't really understand why at the moment.

First, the problem is that fit does exactly what its told - we tell it to fit the last pgf min and max x and y, and it does exactly that (can be seen by changing into draw=red of fitting node):

test43.png

The problem seems to be, that the rectangle is already transformed by the time it gets to fit, and yet fit isn't aware of the 3D transform.

So I was trying to stop the transform, then do the rectangle fitting node, and then restore the transform - didn't work; tried to look for a way to group pgf drawing commands, and then apply a transform to all of them - couldn't find that.

Then I found #47797 How to establish node-anchor-like points on a (tikz) rectangle path (is there a better method than the one described)?, and used that so that coordinate anchors are added to the rectangle - and among other things, tried fit to the anchors of the rectangle... And suddenly it works?? And I cannot see how that would interrupt coordinate transformation, as was my theory for the problem above??

Nevertheless, the output now is:

test44.png

... and while unfortunately, I will not be able to just change the fitting node style and move on (I'll have to add references to rectangles and corresponding fitting nodes everywhere) -- the code also works the same way it did in TikzEdt GUI, so that is good. The code is:

\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}
\usetikzlibrary{3d}

\makeatletter
%http://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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.