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.

Why isn’t it possible (or: how it is possible) to set the size, minimum width etc. of a node relative to the coordinate system. Id would like to type minimum width=2 and get a node that is as wide as two steps in the current coordinate system. But the option is ignored if it gets a value without a dimension.

I coud workaround with the fit library but that will cause lots of extra coordinates and be inconvinient …

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{fit}

\begin{document}
\begin{tikzpicture}[thick,x=1.765cm,y=0.567cm]
   \draw [help lines] (0,0) grid (6,4);
   \draw [help lines,orange,xstep=1.765cm,ystep=0.567cm] (0,0) grid (6,4);
   \node at (1,1) [draw=red, anchor=south west, minimum width=4,
      minimum height=2] {};
   % inconvient way
   \path (1,1) coordinate (LL) ++(4,2) coordinate (UR);
   \node [draw=blue, fit=(LL) (UR), inner sep=0pt] {};
\end{tikzpicture}
\end{document}

result

I’d like to see an easy and short way to make the red node as big as the blue one. Even with a special coordinate system like the one above

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

It's not possible, and it's not in the spirit of TikZ. A node is normally used to contain text, and if you read the pgfmanual you can see that some values confirm what I wrote : inner sep initially .3333em. The dimensions of a node can't be transformed ( except with transform shape or scale for a node) when you change the units because the dimensions of a node are normally determined by the text inside. There are some workarounds like the fit library or the answer of percusse but I think these solutions are very expansive.

A possibility

\documentclass{article}
\usepackage{tikz}

\begin{document} 
  \def\ux{1.765cm}\def\uy{0.567cm} 
\begin{tikzpicture}[thick,
                    x=\ux,
                    y=\uy]
   \draw [help lines] (0,0) grid (6,4);
   \draw [help lines,orange,xstep=\ux,
                            ystep=\uy] (0,0) grid (6,4);
   \node at (1,1) [draw=red, 
                   anchor=south west, 
                   minimum width = 4*\ux,
                   minimum height= 2*\uy] {};
\end{tikzpicture}
\end{document}  
share|improve this answer
    
Thank you! I think your example is the easiest and best readable way :-) –  Tobi Apr 6 '12 at 20:46
add comment

You can use bare coordinates inside the fit mechanism: they don't have to be coordinatised coordinates. The only catch is that if you want to specify them relative to the at position then you have to use the syntax \path (1,1) node [fit = ... rather than \node at (1,1) [fit = .... This is because the at coordinate is ignored in the fit, and because the coordinate is processed at a different time so isn't available when the fit is parsed.

Here's your example using this mechanism:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}

\begin{document}
\begin{tikzpicture}[thick,x=1.765cm,y=0.567cm]
   \draw [help lines] (0,0) grid (6,4);
   \draw [help lines,orange,xstep=1.765cm,ystep=0.567cm] (0,0) grid (6,4);
   \path (1,1) node [draw=red, anchor=south west, fit={+(0,0) +(4,2)}] {};
   \fill (1,1) circle[radius=2pt] +(4,2) circle[radius=2pt];
\end{tikzpicture}
\end{document}

To get a tight fit, set inner set to 0pt. The fill is to show that the coordinates used are the expected ones.

Result:

fit with raw coordinates

share|improve this answer
add comment

You can do this by scoping the scaled drawings and apply a general transformation but according to the manual minimum height/width expects a dimension. If this is not a problem then it is possible to do it with either TikZ version cm or the verbose PGF option \pgftransformcm However, the node options are still measured in absolute terms so the units are not scaled after being declared. To transform them into the new coordinate system you have to use the transform shape key. But this would scale also the text size so there is no free lunch with such simple operation.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[cm={1.765,0,0,0.567,(0,0)}]
\draw [help lines,orange] (0,0) grid (6,4);
\node at (1,1) [draw=red, anchor=south west, minimum width=4cm,minimum height=2cm,transform shape] {};
\end{tikzpicture}
\end{document}

Here is another example with scoping and PGF version of the transform

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\pgftransformcm{1.765}{0}{0}{0.567}{\pgfpointorigin}
\draw [help lines,thick,red] (0,0) grid (6,4);
\node at (1,1) [draw=yellow, anchor=south west, minimum width=4cm,minimum height=2cm,transform shape] {};
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Looks nice but it stretches the text inside nodes too :-( –  Tobi Apr 6 '12 at 16:10
    
You can have a workaround by putting a label with label={center:AAA}. Not the best solution but can be included in a customized macro –  percusse Apr 6 '12 at 16:20
    
OK, I didn’t know that the label is above the transform shape mechanism. BTW: Why? That doesn’t make sense to me … –  Tobi Apr 6 '12 at 16:23
    
It's kind of counterintuitive but label places another node which does not have transform shape as an option. If you want a compliant label then we need to say label={[transform shape]center:AAA} or simply use every node style. –  percusse Apr 6 '12 at 16:28
    
Hm … thanks. I know that label is a node internally but I thought that transform shape transforms the whole canvas (of the current scope). SO yes this is counterintuitive … –  Tobi Apr 6 '12 at 17:12
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.