Does TikZ have a copy
command? the copy command means, e.g.,
I draw a rectangle first, then I draw whatever e.g., circle, writing text etc. in the rectangle. let me define a source object
that includes all objects in the rectangle and the rectangle itself. Now I want to copy
the source object
based on the lower left corner of rectangle to a new position.
@Martin @Jan @Caramdir, following is an example, but it has some error. please also refer to my comment.
\documentclass[titlepage,a4paper]{article}
\usepackage[english]{babel}
\usepackage{TikZ} %Create PostScript and PDF graphics in TeX
\begin{document}
\begin{tikzpicture}[scale=0.962661,thick]
\foreach \xbase/\ybase in {0mm/0mm,46.700000mm/0mm}
{
%grid line
\draw[xstep=11.200000mm,ystep=12.051000mm] (\xbase,\ybase) grid (\xbase + 44.800000mm,\ybase + 36.153000mm);
}
\end{tikzpicture}
\end{document}
@Martin @Jan @Caramdir, i updated the above example. it is better except that the most left vertical line of right grid is missing.
\documentclass[titlepage,a4paper]{article}
\usepackage[english]{babel}
\usepackage{TikZ} %Create PostScript and PDF graphics in TeX
\begin{document}
\begin{tikzpicture}[scale=0.962661,thick]
\foreach \xbase/\ybase/\xoffset in {0mm/0mm/0mm,44.800000mm/0mm/1.9mm}
{
%grid line
\draw[xstep=11.200000mm,ystep=12.051000mm,xshift=\xoffset] (\xbase,\ybase) grid (\xbase + 44.800000mm,\ybase + 36.153000mm);
}
\end{tikzpicture}
\end{document}
it seemed that grid
always uses the origin (0,0) as its reference. my way is to add shift to the base point and cares about the coordinates by myself. but the most left vertical line of right grid is missing. i don't know why. it looked like that the line should be in the range of the grid.
is there a rationale for this? i mean make grid
use (x,y) instead of (0,0) as the reference point.
Best Answer
Other than using the
\foreach
command or defining a new command, you may repeat pictures by at least two other ways. (solution to the grid problem is found at the end of my answer)1- (not tikz specific) : use the
\newsavebox
,\savebox
and\usebox
commands. The advantage of savebox is that the picture is not redrawn everytime it is called. For example:2- (tikz specific) Use the object-oriented capabilities of tikz and pgf. The details are found in the tikz manual. For example, the code found on page 554 of the manual:
About the grid problem. I don't have a good explanation about why the problem is occurring other than the shift in coordinates isn't being treated by tikz the way you expect them to (not much of an explanation I admit). A good way to solve the problem is to use the
scope
environment, and shift the whole environment, as described by the following code (I somewhat simplified your loop to make thescope
environment stand out):The
scope
environment acts as box that may be moved around (shifted or rotated) as a whole. If you are familiar withpstricks
, it is similar to the\rput
command.