是否可以使用 xshift 和一个变量来放置具有可变等距的多个(不同)路径。我想配置路径之间的空间,因此在范围内给 xshift 一个变量就可以了。不幸的是,由于路径不同,我无法使用 foreach。
\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}
编辑:添加了示例
答案1
我不确定我是否理解了您的要求,但您可以定义一个首字母lenght
,然后使用它。
例如,我使用相同的代码通过更改以下内容重现了您的图片三次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}
给你: