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.

In TikZ, picture is drew based on the point (0,0). if my whole picture is based on the point, e.g., (20,0)? how can i draw it easily? it is better to transform the reference point from (0,0) to (20.0). i tried this:

  \begin{tikzpicture}[shift={(20mm,0)}]

but it didn't work. shift works for many commands, but it seems that it doesn't work for environment. it is not good to add shift option to every command.

@Martin: adding shift with scope seemed to have no influence on the whole picture. i want the two grids to move to the right. for the whole picture, there will have many other items. to construct the picture easily, it is better to refer to the point (0,0). but for the whole picture display, it is better to put it based on the point (20,0)

\documentclass[titlepage,a4paper]{article}

\usepackage{tikz}
\usepackage[lmargin=2.500000cm,rmargin=2.500000cm,tmargin=2.500000cm,bmargin=2.500000cm]{geometry}

\begin{document}
\section[General remarks]{General remarks}
\subsection[Geometry and coordinate system]{Geometry and coordinate system}
The main layout of the structure is adopted:\\

\begin{tikzpicture}[scale=1,thick]
  \begin{scope}[shift={(20mm,0)}]
    \foreach \xoffset in {0,5.2}
    {
      \begin{scope}[shift={(\xoffset,0)}]
      \draw[xstep=1,ystep=1] (0,0) grid (5,5);
      \end{scope}
    }
  \end{scope}
\end{tikzpicture}
\end{document}
share|improve this question
add comment

3 Answers

up vote 6 down vote accepted

Shifting the whole picture doesn't make much sense. TikZ cuts every picture to its minimal bounding box. Therefore drawing from e.g. (0,0) to (10,10) or from (100,100) to (110,110) will give you the same visual result!

If you want to "move the picture 20mm to the right" you can put an otherwise empty path which includes (-20mm,0), so that the bounding box will be extended for this amount:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\section[General remarks]{General remarks}
\subsection[Geometry and coordinate system]{Geometry and coordinate system}
The main layout of the structure is adopted:\\

\begin{tikzpicture}[thick,scale=1]
    \path (-20mm,0);
    \foreach \xoffset in {0,5.2}
    {
      \begin{scope}[shift={(\xoffset,0)}]
      \draw[xstep=1,ystep=1] (0,0) grid (5,5);
      \end{scope}
    }
\end{tikzpicture}
\end{document}

If this isn't what you want tell me please.

share|improve this answer
    
but it didn't work. –  warem Mar 2 '11 at 8:03
    
@warem: I see I misunderstood your question. However It doesn't make that much sense to shift the complete picture! Nevertheless shift should work. Try to place the whole picture content into a scope environment with the shift option. –  Martin Scharrer Mar 2 '11 at 8:08
    
it still didn't work. i added a small example in the original text. please have a look. –  warem Mar 2 '11 at 8:44
    
it worked. thank you. –  warem Mar 2 '11 at 10:10
add comment

The issue, I think, is to do with the internal and external specifications of the picture. When you draw a picture using TikZ then you scribble lots of stuff all over the page, using whatever coordinates you like. When you've finished, TikZ very nicely goes around your picture with a pair of scissors and cuts it out. It then hands it over to the TeX page layout builder and says, "Here's your picture.". The TeX page layout builder just gets the picture as-is and doesn't look closely at it. Indeed, as far as the layout builder is concerned, the picture could just be a frame. In particular, the layout builder doesn't look to see what coordinates you used in designing your picture.

So if you want your picture placed somewhere particular on the page, it's not TikZ that you need to talk to, but the layout builder. A simple way would be to tell her to put a big blank space in front of it, aka \hspace{2cm} (or \hspace*{2cm} if the former gets ignored).

It is possible to do what you want from within TikZ, though, by making the picture effectively bigger. Then when TikZ goes round with his scissors, he cuts the frame that he thinks is there whether or not there is actually anything in the picture (he's a bit dumb, you see).

Slightly less prosaically, in your picture then there is nothing at (0,0) so it gets ignored when computing the picture size. If you put something there then it will not be ignored. The trick is to put something there but to do it in a way that is actually nothing. (It's a bit like the emptyset in mathematics: it is nothing, but the fact that it is nothing is still something.)

Here's one way:

\documentclass[titlepage,a4paper]{article}

\usepackage{tikz}
\usepackage[lmargin=2.500000cm,rmargin=2.500000cm,tmargin=2.500000cm,bmargin=2.500000cm]{geometry}

\begin{document}
\section[General remarks]{General remarks}
\subsection[Geometry and coordinate system]{Geometry and coordinate system}
The main layout of the structure is adopted:\\

\begin{tikzpicture}[scale=1,thick]
\path (0,0); % <--- THIS LINE IS ADDED
  \begin{scope}[shift={(20mm,0)}]
    \foreach \xoffset in {0,5.2}
    {
      \begin{scope}[shift={(\xoffset,0)}]
      \draw[xstep=1,ystep=1] (0,0) grid (5,5);
      \end{scope}
    }
  \end{scope}
\end{tikzpicture}
\end{document}

Result:

Shifted grids

share|improve this answer
    
it worked. thank you for your clear concept explanation. –  warem Mar 2 '11 at 10:11
add comment

If I understand correctly tikz behaviour, the picture is actually shifted, but at the end the picture is cropped so that the only remaining parts are those that contain some drawing. To obtain what you ask, you could explicitely set a bounding box using '\useasboundingbox' command as in:

\begin{tikzpicture}[scale=1,thick]
  \useasboundingbox (0,0) rectangle (70mm,5);
  \begin{scope}[shift={(20mm,0)}]
    \foreach \xoffset in {0,5.2}
    {
      \begin{scope}[shift={(\xoffset,0)}]
      \draw[xstep=1,ystep=1] (0,0) grid (5,5);
      \end{scope}
    }
  \end{scope}
\end{tikzpicture}
share|improve this answer
    
This has the major drawback that the bounding box must be given manually in advanced. It would be better to modify the final bounding box at the very end using the special current bounding box node. See also my updated answer. –  Martin Scharrer Mar 2 '11 at 9:59
    
your method also worked. thank you. –  warem Mar 2 '11 at 10:14
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.