Graphics, Figures & TablesPlacement of TikZ pictures within TikZ pictures

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Speldosa
Posts: 2
Joined: Sun Oct 31, 2010 6:58 pm

Placement of TikZ pictures within TikZ pictures

Post by Speldosa »

Hello!

I'm new to PGF and TikZ, that is, I've been poking around with it for the last couple of days, slowly going through the manual. In my efforts, I've always looked for an easy way to create and position different element relative to each other.

Here, let me show you what I mean. Let's say I have this:

Code: Select all

\documentclass[12pt]{article}

\usepackage{tikz}

\begin{document}

\tikzset{test/.style={circle, draw=black}}
\begin{figure}
\centering		
\begin{tikzpicture} [scale=1, every node/.style={scale=1}]
	\node[test] at (0,0)		(node1-1)			{1}; 
	\node[test] at (0,-2)		(node1-2)			{2}; 
	\node[test] at (2,-2)		(node1-3)			{3}; 
	\node[test] at (2, 0)		(node1-4)			{4}; 
\end{tikzpicture}
\begin{tikzpicture} [scale=1, every node/.style={scale=1}]
	\node[test] at (0,0)		(node2-1)			{1}; 
	\node[test] at (0,-2)	(node2-2)			{2}; 
	\node[test] at (2,-2)		(node2-3)			{3}; 
	\node[test] at (2, 0)		(node2-4)			{4}; 
\end{tikzpicture}
\end{figure}

\end{document}
Ok. As we can see, we get two similar sets of nodes placed right beside each other. If I wanted to increase the space between the set of nodes, I could, for example, ad a "\quad" between them, but this operation isn't totaly stable. That is, if I would have to many elements with "\quad” between them, the elements would start to pop up underneath each other.

So, let me show you what it is that I would like to do with a mock-up example (this code isn't compilable since I made up the syntax myself).

Code: Select all

\documentclass[12pt]{article}

\usepackage{tikz}

\begin{document}

\tikzset{test/.style={circle, draw=black}}
\begin{figure}
\centering	
\begin{tikzpicture}

\begin{element}[place at cordinate (0,0), scale=1]
\begin{tikzpicture} [scale=1, every node/.style={scale=1}]
	\node[test] at (0,0)		(node1-1)			{1}; 
	\node[test] at (0,-2)		(node1-2)			{2}; 
	\node[test] at (2,-2)		(node1-3)			{3}; 
	\node[test] at (2, 0)		(node1-4)			{4}; 
\end{tikzpicture}
\end{element}

\begin{element}[place at cordinate (0,4), scale=1]
\begin{tikzpicture} [scale=1, every node/.style={scale=1}]
	\node[test] at (0,0)		(node2-1)			{1}; 
	\node[test] at (0,-2)	(node2-2)			{2}; 
	\node[test] at (2,-2)		(node2-3)			{3}; 
	\node[test] at (2, 0)		(node2-4)			{4}; 
\end{tikzpicture}
\end{element}

\end{tikzpicture}

\end{figure}

\end{document}
See what I want to do? I would like to place TikZ-pictures within a TikZ-picture, using the top-level TikZ-environment's coordinate system as the global reference point, but still keeping local coordinate systems within the new TikZ-environments I create.

Now, what I'm searching for isn't an detailed example how to do this, but rather where I should look. How do people solve this? I'm open to the possibility that I'm on the complete wrong track here. In that case, please correct me.

For example, I want to create an array of a 16 small networks, place them in a 4 by 4 fashion, take this array and stick it above a similar type och array and still have space to the left for placement of new elements. Right now, I don't really see how I could do this, despite having searched the internet (including this forum) and the manual for a couple of days now.

I'm happy for any kind of answers that can point me in the right direction!
Last edited by Speldosa on Tue Nov 02, 2010 1:46 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Placement of TikZ pictures within TikZ pictures

Post by localghost »

Use the scope environment as described in the pgf/tikZ manual (Section 2.18 and 2.19) or as shown below.

Code: Select all

\documentclass{minimal}
\usepackage{tikz}

\tikzset{test/.style={circle,draw=black}}

\begin{document}
  \begin{tikzpicture}
    \node[test] at (0,0)  (node1-1) {1};
    \node[test] at (0,-2) (node1-2) {2};
    \node[test] at (2,-2) (node1-3) {3};
    \node[test] at (2, 0) (node1-4) {4};
    \begin{scope}[shift={(0,4)}]
      \node[test] at (0,0)  (node2-1) {1};
      \node[test] at (0,-2) (node2-2) {2};
      \node[test] at (2,-2) (node2-3) {3};
      \node[test] at (2, 0) (node2-4) {4};
    \end{scope}
  \end{tikzpicture}
\end{document}
The shift option creates a new origin for the graphics elements inside the scope environment and allows in principal a picture within a picture.


Best regards and welcome to the board
Thorsten
Speldosa
Posts: 2
Joined: Sun Oct 31, 2010 6:58 pm

Re: Placement of TikZ pictures within TikZ pictures

Post by Speldosa »

This seems to be exactly what I was looking for. Thanks a million Thorsten! You've saved me a lot of frustration :)

I will poke around with this one to see if I can get all my desired results but on the face of it, it looks spot on. I'll re-open the thread if I run into major problems, but otherwise; thanks!
Post Reply