3

I want to draw several complex drawings and put them all together in a bigger TikZ drawing. How do I do that?

So far, this is what I have done:

\documentclass[preview]{standalone}

\begin{document}
\begin{tikzpicture}
  \draw[help lines] (0,0) grid (10, 10);

  \node (rectifier) at (0,0) {
    \begin{tikzpicture}
      \node (sine) at (1.25,3) {
        \begin{tikzpicture}[scale=0.4]
          \draw (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0);
        \end{tikzpicture}
      };
      \node (rect) at (2.75,1) {
        \begin{tikzpicture}[scale=0.4]
          \draw (0,2) sin ++(1,1) cos (2,2) sin (3,3) cos (4,2) ;
        \end{tikzpicture}
      };
      \draw (0,0) rectangle (4,4) -- (0,0);
    \end{tikzpicture}
  };
\end{tikzpicture}
\end{document}

Problem:
I want the whole (rectifier) box and all its contents to be scalable from the top level, like so:

\node (rectifier) at (0,0) {
  \begin{tikzpicture}[scale=0.5]
  ...
  ...
  ...

But it scales only the box, and not the sinusoid drawings.

Extension:
Is there an "object-oriented" paradigm in TikZ, where I can declare classes of objects and simply instantiate them in a bigger drawing?

  • Try using a macro as opposed to a complete tikzpicture. – Peter Grill Apr 3 '13 at 4:42
  • Can you please post (a link to) an image showing the desired final object? – Gonzalo Medina Apr 3 '13 at 5:11
  • I suppose that you need to add transform shape whenever you try to scale something which is inside of nodes. Does this help? – Christian Feuersänger Apr 3 '13 at 7:04
2

First of all, you are placing pictures within nodes. While this works and in many times it is what must be done, it is delicate to use when transformations must be applied.

Second item, conceptually your diagram seems to be things on the same "level", just at different places. The scope environment is better suited for what you want.

The third thing is yes, there is an object-oriented structure in tikz. I don't use it (and judging by most of the answers on this site, most people don't use it). You can find information in the manual.

A version of your code using scope is :

\documentclass[preview]{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\draw[help lines] (0,0) grid (10, 10);

\begin{scope}[scale=0.5]

\draw[green,shift={(1.25,3)}] (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0);  
\draw[blue,shift={(2.75,1)}] (0,2) sin ++(1,1) cos (2,2) sin (3,3) cos (4,2) ;

\draw (0,0) rectangle (4,4) -- (0,0);

\end{scope}

%The same stuff, but shifted, to show you can shift a whole picture 
\begin{scope}[scale=0.5,shift={(5,5)}]

\draw[green,shift={(1.25,3)}] (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0);  
\draw[blue,shift={(2.75,1)}] (0,2) sin ++(1,1) cos (2,2) sin (3,3) cos (4,2) ;

\draw (0,0) rectangle (4,4) -- (0,0);

\end{scope}

\end{tikzpicture}
\end{document}
  • Ah long time no see :) – percusse Apr 7 '13 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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