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.

Usually I can specify a node location relative to location of another node, e.g., using left of and alike

\usepackage{tikz}
\usetikzlibrary{positioning}
...
\matrix (first) [left of=arrow, matrix of math nodes, ampersand replacement=\&,
  left delimiter=\|, right delimiter=\|, xshift=-2.5cm] {
...

Now I want to plot two simple figures using tkz-collection separated by a node with text vs. However I want to show same domain, i.e., I want to have same coordinates in \tkzInit. I thought I can isolate coordinates conflict using scope but it does not look like the case.

Is the coordinate space defined by \tkzInit global for entire tikzpicture? Shall I use overlay to somehow combine 2 figures?

Here is what I've tried

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{tkz-fct}

\begin{document}

\begin{tikzpicture}
\begin{scope}
\tkzInit[xmin=-3,xmax=3,xstep=2, ymin=-3,ymax=3,ystep=2]
\tkzGrid[sub,subxstep=1,subystep=1](-2,-2)(2,2)
\tkzAxeXY
\node (a) at (3,0) {hello};
\end{scope}

\begin{scope}
\tkzInit[xmin=-3,xmax=3,xstep=2, ymin=-3,ymax=3,ystep=2]
\tkzGrid[sub,subxstep=1,subystep=1](-2,-2)(2,2)
\tkzAxeXY
\node[right=5cm of a] (b) at (3,0) {hello};
\end{scope}

\end{tikzpicture}

\end{document}

I see 2 separated *hello*s but only a single figure.

share|improve this question
    
Can you make your code a full compilable one by adding a few more lines? –  percusse Oct 4 '12 at 1:42
1  
@mlt Both scopes are typesets, on top of each other. Put for example [xshift=6cm] to the second scope. –  Qrrbrbirlbel Oct 4 '12 at 1:46
    
@Qrrbrbirlbel Awesome! Thanks. This made a trick. Though I feel like I'm still missing all these coordinates issues how those work together with nodes. I guess I can always shift & scale tkz stuff to wherever I want. –  mlt Oct 4 '12 at 1:51
    
@mlt You could also do \begin{tikzpicture}[node distance=6cm]\begin{scope}[name=scope1] … \end{scope} \begin{scope}[right of=scope1] … \end{scope} \end{tikzpicture}. Then just put \node (vs) at (3,0) {vs}; outside of both scopes. Though, I'm not sure how TikZ handles named scopes, right=6cm of scope1 warns with No shape named scope1 is known. :( –  Qrrbrbirlbel Oct 4 '12 at 2:13
    
Another thing: The node specifications [right=of …] and at (x,y) look like two conflicting settings. –  Qrrbrbirlbel Oct 4 '12 at 2:17

1 Answer 1

up vote 3 down vote accepted

As mentioned in the comments, use \xshift option on the second scope environment. As commented by Qrrbrbirlbel, you can also remove the at (x,y) specification. Also, I have cleaned up the preamble a bit. tkz-fct automatically loads tikz

\documentclass{article}

\usepackage{tkz-fct}
\usetikzlibrary{positioning}


\begin{document}

\begin{tikzpicture}
\begin{scope}
\tkzInit[xmin=-3,xmax=3,xstep=2, ymin=-3,ymax=3,ystep=2]
\tkzGrid[sub,subxstep=1,subystep=1](-2,-2)(2,2)
\tkzAxeXY
\node (a) at (3,0) {hello};
\end{scope}

\begin{scope}[xshift=5cm]
\tkzInit[xmin=-3,xmax=3,xstep=2, ymin=-3,ymax=3,ystep=2]
\tkzGrid[sub,subxstep=1,subystep=1](-2,-2)(2,2)
\tkzAxeXY
\node (b) at (3,0) {hello};
\tkzText[above,color=red](3,0){hello}
\end{scope}
\end{tikzpicture}

\end{document}

enter image description here

You can see the definition of \tkzInit in \tkz-tools-base.tex. I can't understand most of it though. :)

Also the use of \xshift and coordinate transformations in general are explained in page 250 of the pgf manual. It says that any specified coordinate is first "reduced" to a position of the form "x points to the right and y points upwards." ... The next step is to apply the current coordinate transformation matrix to the coordinate." This means that for the second scope, each original x coordinate is transformed.

Update The tkz collection has a command for placing text: \tkzText. I have modified the code with tkzText on the second scope just for comparison.

Edit I can finally say that it is not a bug. The behavior was caused by the xstep and ystep options. Here is the revised MWE. I did not delete the previous one for comparison.

\documentclass{article}

\usepackage{tkz-fct}

\begin{document}

\begin{tikzpicture}
\begin{scope}
\tkzInit[xmin=-3,xmax=3,xstep=1, ymin=-3,ymax=3,ystep=1]
\tkzGrid[sub,subxstep=1,subystep=1](-2,-2)(2,2)
\tkzAxeXY
\node (a) at (3,0) {hello};
\end{scope}

\begin{scope}[xshift=8cm]
\tkzInit[xmin=-3,xmax=3,xstep=1, ymin=-3,ymax=3,ystep=1]
\tkzGrid[sub,subxstep=1,subystep=1](-2,-2)(2,2)
\tkzAxeXY
\node (b) at (3,0) {hello};
\tkzText[above,color=red](3,0){hello}
\end{scope}
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
Any ideas as why 'hello' is not at (3,0) on the plot and how to make it happen? I'd wait with acceptance in case @Qrrbrbirlbel wants to claim points for the answer. –  mlt Oct 4 '12 at 3:38
    
@hpesoj626 It's not a bug. \node (b) at (3,0) is a TiKZ command and 3 means 3cm, while \tkzText(3,0) is a tkz command where 3 means 3 tkz units which seems to be 0.5cm (I don't know why, never used it). If you use \draw (0,0) grid (10,5) before first scope you will see the difference. –  Ignasi Oct 4 '12 at 7:18
    
@hpesoj626 So may be it's a bug. I've never used \tkcFct before testing your code. If you draw the grid you will see that hello is well placed according TiKZ. May be you could write a new question commenting it. –  Ignasi Oct 4 '12 at 7:28

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.