
새로운 것을 begin{tikzpicture}[xshift=2cm]
사용하면 기존 TikZ 그림의 오른쪽 2cm에 TikZ 그림이 생성됩니다(X 이동).
그런데 왠지 여기서는 안되는 것 같고, 장식(뱀선)도 제대로 정렬되지 않은 것 같습니다.
나는 다음을 기대했습니다.
하지만 나는 이것을 얻습니다:
메모: 첫 번째 TikZ 그림에서 동일한 코드를 사용했으므로 오른쪽 상자에도 동일한 다이어그램이 있습니다. 나중에 바꾸겠습니다.
암호:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{backgrounds}
\usetikzlibrary{fit}
\usetikzlibrary{decorations.pathmorphing}
\tikzset{squarenode/.style = {
shape = rectangle,
fill = gray!50,
draw = black,
thick,
minimum height = 1cm,
minimum width = 1cm
}}
\tikzset{circlenode/.style = {
shape = circle,
fill = blue!20,
draw = blue,
thick,
minimum size = 1cm
}}
\tikzset{help lines/.style=very thin}
\tikzset{My Grid/.style={help lines,color=blue!50}}
\begin{document}
\begin{tikzpicture}
[>=stealth']
%\draw[My Grid] (-5,-5) grid (15,15);
\node (r1) at (-4,4) [squarenode] {r1};
\node[right=4cm of r1] (r2) [squarenode] {r2};
\node[below=3cm of r1] (r3) [squarenode] {r3};
\node[right=4cm of r3] (r4) [squarenode] {r4};
\node[right=1.5cm of r1] (s2) [circlenode] {s2};
\node[above=1cm of s2] (s1) [circlenode] {}; %s1
\node[below=1cm of s2] (s3) [circlenode] {s3}; %s3
\node[above=1ex of s3,red] {$s \leq 3$};
\node[right=1.5cm of r3] (s4) [circlenode] {s4};
\node[below=1cm of s4] (s5) [circlenode] {}; %s5
\draw[fill=black] (s1.center) circle [radius=0.1cm];
\draw[fill=black] (s5.center) circle [radius=0.1cm];
\draw[->] (r1) -- (s2);
\draw[->] (s2) -- (r2);
\draw[->] (r3) -- (s4);
\draw[->] (s4) -- (r4);
\draw[->] (s1) to [out=180,in=90] (r1);
\draw[->] (r1) to [out=-90,in=180] (s3);
\draw[->] (s3) to [out=0,in=-90] (r2);
\draw[->] (r2) to [bend right=45] node[auto,swap] {2} (s1);
\draw[->] (r3) to [out=90,in=180] (s3);
\draw[->] (s3) to [out=0,in=90] (r4);
\draw[->] (r4) to [bend left=45] node[auto] {2} (s5);
\draw[->] (s5) to [bend left=45] (r3);
\begin{scope}[on background layer]
\node [fill=gray!15,rounded corners,fit=(s1) (s3) (s5) (r1) (r2)] (R1) {};
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}[xshift=5cm]
[>=stealth']
%\draw[My Grid] (-5,-5) grid (15,15);
\node (r1) at (-4,4) [squarenode] {r1};
\node[right=4cm of r1] (r2) [squarenode] {r2};
\node[below=3cm of r1] (r3) [squarenode] {r3};
\node[right=4cm of r3] (r4) [squarenode] {r4};
\node[right=1.5cm of r1] (s2) [circlenode] {s2};
\node[above=1cm of s2] (s1) [circlenode] {}; %s1
\node[below=1cm of s2] (s3) [circlenode] {s3}; %s3
\node[above=1ex of s3,red] {$s \leq 3$};
\node[right=1.5cm of r3] (s4) [circlenode] {s4};
\node[below=1cm of s4] (s5) [circlenode] {}; %s5
\draw[fill=black] (s1.center) circle [radius=0.1cm];
\draw[fill=black] (s5.center) circle [radius=0.1cm];
\draw[->] (r1) -- (s2);
\draw[->] (s2) -- (r2);
\draw[->] (r3) -- (s4);
\draw[->] (s4) -- (r4);
\draw[->] (s1) to [out=180,in=90] (r1);
\draw[->] (r1) to [out=-90,in=180] (s3);
\draw[->] (s3) to [out=0,in=-90] (r2);
\draw[->] (r2) to [bend right=45] node[auto,swap] {2} (s1);
\draw[->] (r3) to [out=90,in=180] (s3);
\draw[->] (s3) to [out=0,in=90] (r4);
\draw[->] (r4) to [bend left=45] node[auto] {2} (s5);
\draw[->] (s5) to [bend left=45] (r3);
\begin{scope}[on background layer]
\node [fill=gray!15,rounded corners,fit=(s1) (s3) (s5) (r1) (r2)] (R2) {};
\end{scope}
\draw [thick,decorate,
decoration={snake,amplitude=.4mm,segment length=2mm,
pre=moveto,pre length=1mm,post length=2mm}]
(R1) -- (R2) node [above=1mm,midway,text width=3cm,align=center]
{replacement of the \textcolor{red}{capacity} by \textcolor{red}{two places}};
\end{tikzpicture}
\end{document}
답변1
또는 으로 이동하는 xshift
것은 단일 환경 내에서만 작동합니다.yshift
shift
tikzpicture
여기 있습니다.둘tikzpicture 환경에서는아니요효과.
scope
그림을 움직일 수 있는 환경 에 그림을 포함시키는 것으로 충분합니다 .
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{backgrounds}
\usetikzlibrary{fit}
\usetikzlibrary{decorations.pathmorphing}
\tikzset{squarenode/.style = {
shape = rectangle,
fill = gray!50,
draw = black,
thick,
minimum height = 1cm,
minimum width = 1cm
}}
\tikzset{circlenode/.style = {
shape = circle,
fill = blue!20,
draw = blue,
thick,
minimum size = 1cm
}}
\tikzset{help lines/.style=very thin}
\tikzset{My Grid/.style={help lines,color=blue!50}}
\begin{document}
\begin{tikzpicture}
[>=stealth']
%\draw[My Grid] (-5,-5) grid (15,15);
\node (r1) at (-4,4) [squarenode] {r1};
\node[right=4cm of r1] (r2) [squarenode] {r2};
\node[below=3cm of r1] (r3) [squarenode] {r3};
\node[right=4cm of r3] (r4) [squarenode] {r4};
\node[right=1.5cm of r1] (s2) [circlenode] {s2};
\node[above=1cm of s2] (s1) [circlenode] {}; %s1
\node[below=1cm of s2] (s3) [circlenode] {s3}; %s3
\node[above=1ex of s3,red] {$s \leq 3$};
\node[right=1.5cm of r3] (s4) [circlenode] {s4};
\node[below=1cm of s4] (s5) [circlenode] {}; %s5
\draw[fill=black] (s1.center) circle [radius=0.1cm];
\draw[fill=black] (s5.center) circle [radius=0.1cm];
\draw[->] (r1) -- (s2);
\draw[->] (s2) -- (r2);
\draw[->] (r3) -- (s4);
\draw[->] (s4) -- (r4);
\draw[->] (s1) to [out=180,in=90] (r1);
\draw[->] (r1) to [out=-90,in=180] (s3);
\draw[->] (s3) to [out=0,in=-90] (r2);
\draw[->] (r2) to [bend right=45] node[auto,swap] {2} (s1);
\draw[->] (r3) to [out=90,in=180] (s3);
\draw[->] (s3) to [out=0,in=90] (r4);
\draw[->] (r4) to [bend left=45] node[auto] {2} (s5);
\draw[->] (s5) to [bend left=45] (r3);
\begin{scope}[on background layer]
\node [fill=gray!15,rounded corners,fit=(s1) (s3) (s5) (r1) (r2)] (R1) {};
\end{scope}
\begin{scope}[xshift=9cm]
[>=stealth']
%\draw[My Grid] (-5,-5) grid (15,15);
\node (r1) at (-4,4) [squarenode] {r1};
\node[right=4cm of r1] (r2) [squarenode] {r2};
\node[below=3cm of r1] (r3) [squarenode] {r3};
\node[right=4cm of r3] (r4) [squarenode] {r4};
\node[right=1.5cm of r1] (s2) [circlenode] {s2};
\node[above=1cm of s2] (s1) [circlenode] {}; %s1
\node[below=1cm of s2] (s3) [circlenode] {s3}; %s3
\node[above=1ex of s3,red] {$s \leq 3$};
\node[right=1.5cm of r3] (s4) [circlenode] {s4};
\node[below=1cm of s4] (s5) [circlenode] {}; %s5
\draw[fill=black] (s1.center) circle [radius=0.1cm];
\draw[fill=black] (s5.center) circle [radius=0.1cm];
\draw[->] (r1) -- (s2);
\draw[->] (s2) -- (r2);
\draw[->] (r3) -- (s4);
\draw[->] (s4) -- (r4);
\draw[->] (s1) to [out=180,in=90] (r1);
\draw[->] (r1) to [out=-90,in=180] (s3);
\draw[->] (s3) to [out=0,in=-90] (r2);
\draw[->] (r2) to [bend right=45] node[auto,swap] {2} (s1);
\draw[->] (r3) to [out=90,in=180] (s3);
\draw[->] (s3) to [out=0,in=90] (r4);
\draw[->] (r4) to [bend left=45] node[auto] {2} (s5);
\draw[->] (s5) to [bend left=45] (r3);
\begin{scope}[on background layer]
\node [fill=gray!15,rounded corners,fit=(s1) (s3) (s5) (r1) (r2)] (R2) {};
\end{scope}
\draw [thick,decorate,
decoration={snake,amplitude=.4mm,segment length=2mm,
pre=moveto,pre length=1mm,post length=2mm}]
(R1) -- (R2) node [above=1mm,midway,text width=3cm,align=center]
{replacement of the \textcolor{red}{capacity} by \textcolor{red}{two places}};
\end{scope}
\end{tikzpicture}
\end{document}
답변2
위에서 언급한 것처럼 xshift
오버레이 그림과 절대 위치 지정을 사용하여 작업하지 않는 한 그림을 이동하지 마십시오. 여기서는 그럴 필요가 없습니다 . fit
를 사용하여 수행하는 것이 더 쉽습니다 local bounding box
. 이러한 로컬 경계 상자를 이동할 수 있습니다.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{backgrounds}
\usetikzlibrary{decorations.pathmorphing}
\tikzset{squarenode/.style = {
shape = rectangle,
fill = gray!50,
draw = black,
thick,
minimum height = 1cm,
minimum width = 1cm
}}
\tikzset{circlenode/.style = {
shape = circle,
fill = blue!20,
draw = blue,
thick,
minimum size = 1cm
}}
\tikzset{help lines/.style=very thin}
\tikzset{My Grid/.style={help lines,color=blue!50}}
\begin{document}
\begin{tikzpicture}[>=stealth']
\begin{scope}[local bounding box=L]
%\draw[My Grid] (-5,-5) grid (15,15);
\node (r1) at (-4,4) [squarenode] {r1};
\node[right=4cm of r1] (r2) [squarenode] {r2};
\node[below=3cm of r1] (r3) [squarenode] {r3};
\node[right=4cm of r3] (r4) [squarenode] {r4};
\node[right=1.5cm of r1] (s2) [circlenode] {s2};
\node[above=1cm of s2] (s1) [circlenode] {}; %s1
\node[below=1cm of s2] (s3) [circlenode] {s3}; %s3
\node[above=1ex of s3,red] {$s \leq 3$};
\node[right=1.5cm of r3] (s4) [circlenode] {s4};
\node[below=1cm of s4] (s5) [circlenode] {}; %s5
\draw[fill=black] (s1.center) circle [radius=0.1cm];
\draw[fill=black] (s5.center) circle [radius=0.1cm];
\draw[->] (r1) -- (s2);
\draw[->] (s2) -- (r2);
\draw[->] (r3) -- (s4);
\draw[->] (s4) -- (r4);
\draw[->] (s1) to[out=180,in=90] (r1);
\draw[->] (r1) to[out=-90,in=180] (s3);
\draw[->] (s3) to[out=0,in=-90] (r2);
\draw[->] (r2) to[bend right=45] node[auto,swap] {2} (s1);
\draw[->] (r3) to[out=90,in=180] (s3);
\draw[->] (s3) to[out=0,in=90] (r4);
\draw[->] (r4) to[bend left=45] node[auto] {2} (s5);
\draw[->] (s5) to[bend left=45] (r3);
\end{scope}
\begin{scope}[on background layer]
\fill[gray!15,rounded corners] (L.south west) rectangle (L.north east);
\end{scope}
\begin{scope}[xshift=8.5cm,local bounding box=R]
%\draw[My Grid] (-5,-5) grid (15,15);
\node (r1) at (-4,4) [squarenode] {r1};
\node[right=4cm of r1] (r2) [squarenode] {r2};
\node[below=3cm of r1] (r3) [squarenode] {r3};
\node[right=4cm of r3] (r4) [squarenode] {r4};
\node[right=1.5cm of r1] (s2) [circlenode] {s2};
\node[above=1cm of s2] (s1) [circlenode] {}; %s1
\node[below=1cm of s2] (s3) [circlenode] {s3}; %s3
\node[above=1ex of s3,red] {$s \leq 3$};
\node[right=1.5cm of r3] (s4) [circlenode] {s4};
\node[below=1cm of s4] (s5) [circlenode] {}; %s5
\draw[fill=black] (s1.center) circle [radius=0.1cm];
\draw[fill=black] (s5.center) circle [radius=0.1cm];
\draw[->] (r1) -- (s2);
\draw[->] (s2) -- (r2);
\draw[->] (r3) -- (s4);
\draw[->] (s4) -- (r4);
\draw[->] (s1) to [out=180,in=90] (r1);
\draw[->] (r1) to [out=-90,in=180] (s3);
\draw[->] (s3) to [out=0,in=-90] (r2);
\draw[->] (r2) to [bend right=45] node[auto,swap] {2} (s1);
\draw[->] (r3) to [out=90,in=180] (s3);
\draw[->] (s3) to [out=0,in=90] (r4);
\draw[->] (r4) to [bend left=45] node[auto] {2} (s5);
\draw[->] (s5) to [bend left=45] (r3);
\end{scope}
\begin{scope}[on background layer]
\fill[gray!15,rounded corners] (R.south west) rectangle (R.north east);
\end{scope}
\draw [thick,decorate,
decoration={snake,amplitude=.4mm,segment length=2mm,
pre=moveto,pre length=1mm,post length=2mm}]
(L) -- (R) node [above=1mm,midway,text width=3cm,align=center]
{replacement of the \textcolor{red}{capacity} by \textcolor{red}{two places}};
\end{tikzpicture}
\end{document}