3

Is it possible to use xshift and a variable to place several (different) paths with variable equidistance. I want to configure the space between the paths so giving a variable e.g. to xshift in scope would do the trick. Unfortunately I cannot use foreach since the paths are different.

\documentclass[a4paper]{article}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric,positioning}

\begin{document}

\usetikzlibrary{calc}

\begin{tikzpicture}%[node distance =4.5cm,thick]

\newcommand{\room} {
 \coordinate (a) at  (0,0) ;
 \coordinate (b) at (5,0);
 \coordinate (c) at  (5,5);
 \coordinate (d) at (0,4);
 \coordinate (e) at (1,3);
 \coordinate (f) at     (1.4,3) ;
 \coordinate (g) at (1.4,2.6)   ;
 \coordinate (h) at (1,2.6) ;
 \coordinate (i) at (1,3)   ;
}


\begin{scope}[xshift=0cm,yshift=-7cm]
    \room;
    \draw[dashed,thick] (b)--(c)--(d)--(e)--(f);
\end{scope}

\begin{scope}[xshift=6cm,yshift=-7cm]
    \room;
    \draw[dashed,thick] (b)--(c)--(d)--(e)--(f) --(g) --(h);
\end{scope}


\begin{scope}[xshift=12cm,yshift=-7cm]  
    \room;
    \draw[densely dotted,very thick] (d)--(e)--(f) --(g) --(h)--(e);
    \draw[dashed,thick] (b)--(c)--(d);
\end{scope}

\end{tikzpicture}
\end{document}

Edit: Added Eaxmple

1

1 Answer 1

2

I'm not sure of having understood well what you are asking for, but you can define an initial lenght and then use this.

For example, I reproduced your picture three times, with the same code, by changing this length:

\documentclass[a4paper]{article}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric,positioning,calc}

\newlength\mydistance % definition
\setlength{\mydistance}{5cm} % first setting

\newcommand{\room} {
 \coordinate (a) at  (0,0) ;
 \coordinate (b) at (5,0);
 \coordinate (c) at  (5,5);
 \coordinate (d) at (0,4);
 \coordinate (e) at (1,3);
 \coordinate (f) at     (1.4,3) ;
 \coordinate (g) at (1.4,2.6)   ;
 \coordinate (h) at (1,2.6) ;
 \coordinate (i) at (1,3)   ;
}

\begin{document}
\begin{tikzpicture}[scale=0.75]
\begin{scope}[xshift=0cm,yshift=-7cm]
    \room;
    \draw[dashed,thick] (b)--(c)--(d)--(e)--(f);
\end{scope}

\begin{scope}[xshift=\mydistance,yshift=-7cm]
    \room;
    \draw[dashed,thick] (b)--(c)--(d)--(e)--(f) --(g) --(h);
\end{scope}


\begin{scope}[xshift=2\mydistance,yshift=-7cm]  
    \room;
    \draw[densely dotted,very thick,] (d)--(e)--(f) --(g) --(h)--(e);
    \draw[dashed,thick] (b)--(c)--(d);
\end{scope}
\end{tikzpicture}

\vspace*{2cm}
\setlength{\mydistance}{5.5cm} % re-set the distance

\begin{tikzpicture}[scale=0.75]
\begin{scope}[xshift=0cm,yshift=-7cm]
    \room;
    \draw[dashed,thick] (b)--(c)--(d)--(e)--(f);
\end{scope}

\begin{scope}[xshift=\mydistance,yshift=-7cm]
    \room;
    \draw[dashed,thick] (b)--(c)--(d)--(e)--(f) --(g) --(h);
\end{scope}


\begin{scope}[xshift=2\mydistance,yshift=-7cm]  
    \room;
    \draw[densely dotted,very thick,] (d)--(e)--(f) --(g) --(h)--(e);
    \draw[dashed,thick] (b)--(c)--(d);
\end{scope}
\end{tikzpicture}

\vspace*{2cm}
\setlength{\mydistance}{7cm} % changed again the distance

\begin{tikzpicture}[scale=0.75]
\begin{scope}[xshift=0cm,yshift=-7cm]
    \room;
    \draw[dashed,thick] (b)--(c)--(d)--(e)--(f);
\end{scope}

\begin{scope}[xshift=\mydistance,yshift=-7cm]
    \room;
    \draw[dashed,thick] (b)--(c)--(d)--(e)--(f) --(g) --(h);
\end{scope}


\begin{scope}[xshift=2\mydistance,yshift=-7cm]  
    \room;
    \draw[densely dotted,very thick,] (d)--(e)--(f) --(g) --(h)--(e);
    \draw[dashed,thick] (b)--(c)--(d);
\end{scope}
\end{tikzpicture}
\end{document}

gives you:

enter image description here

1
  • Thanks! That was exactly what I was looking for but I did not find it in the pgfmanual.
    – Martin
    May 4, 2012 at 16:41

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.