행렬을 표현하기 위해 이중 그래프를 그리고 있습니다.
\begin{figure}
\begin{tikzpicture}[roundnode/.style={circle, draw=black!60, fill=black!5, very thick, minimum size=7mm}]
%Nodes
\node[roundnode] (midcircle) {2};
\node[roundnode] (uppercircle) [above=of midcircle] {1};
\node[roundnode] (rightcircle) [right=of midcircle] {4};
\node[roundnode] (lowercircle) [below=of midcircle] {3};
%Edges out of 1
\draw[->] (uppercircle.east) -- (rightcircle.north);
\draw[->] (uppercircle.west) .. controls+(left:40mm) .. (lowercircle.west);
\draw[->] (uppercircle.west) .. controls +(up:20mm) and +(right:7mm) .. (uppercircle.east);
%2 Edges out of 2
\draw[->] (midcircle.east) -- (rightcircle.west);
\draw[->] (midcircle.north) .. controls +(up:5mm) and +(right:7mm) .. (midcircle.east);
\draw[->] (midcircle.south) -- (lowercircle.north);
\draw[->] (midcircle.north) -- (uppercircle.south);
%Edges out of 3
\draw[->] (lowercircle.west) .. controls+(left:50mm) and +(up:10mm) .. (uppercircle.west);
\draw[->] (lowercircle.east) -- (rightcircle.south);
\draw[->] (lowercircle.south) .. controls +(right:7mm) .. (lowercircle.east);
%Edges out of 4
\draw[->] (rightcircle.south) .. controls +(down:7mm) and +(right:7mm) .. (midcircle.east);
\end{tikzpicture}
\end{figure}
이는
- 단순히 + 또는 -로 가장자리에 레이블을 지정하는 방법을 알고 싶습니다.
- 나는 교차하지 않고 더 대칭적인 더 아름다운 가장자리를 만들고 싶습니다.
controls
명령을 사용하는 것이 최선의 접근 방식인지 확실하지 않습니다 . 또한 가장자리가north
,south
,east
또는 에서 나가고 들어가지 않도록 하는 것이 더 잘 작동할 수도 있습니다west
. 더 나은 방법을 제안해 주시나요?
답변1
라이브러리 로 그린 오토마톤은 다음과 같습니다 automata
. 코드에서 쉽게 식별할 수 있도록 모든 가장자리에 문자를 표시했지만 물론 node{\texttt{+}}
또는 같은 것을 사용할 수도 있습니다 node{$+$}
.
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,positioning}
\begin{document}
\begin{tikzpicture}%
[>=stealth,
shorten >=1pt,
node distance=2cm,
on grid,
auto,
every state/.style={draw=black!60, fill=black!5, very thick}
]
\node[state] (mid) {2};
\node[state] (upper) [above=of mid] {1};
\node[state] (right) [right=of mid] {4};
\node[state] (lower) [below=of mid] {3};
\path[->]
% FROM BEND/LOOP POSITION OF LABEL LABEL TO
(upper) edge[bend left] node {a} (right)
edge[bend right=80] node[swap,very near start]{b} (lower)
edge[loop above] node {c} (upper)
(mid) edge[bend left=10] node {d} (right)
edge[loop left] node {e} (mid)
edge node {f} (lower)
edge node {g} (upper)
(lower) edge[bend left=70] node[swap,very near start]{h} (upper)
edge[bend right] node[swap] {i} (right)
edge[loop below] node {j} (lower)
(right) edge[bend left=10] node {k} (mid)
;
\end{tikzpicture}
\end{document}
답변2
귀하의 질문을 완전히 이해했는지 모르겠지만 여기에 해결책이 있습니다. 물론 최고는 아닙니다.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata,arrows,calc,positioning}
\begin{document}
\begin{figure}
\begin{tikzpicture}[roundnode/.style={circle, draw=black!60, fill=black!5, very thick, minimum size=7mm}]
%Nodes
\node[roundnode] (midcircle) {2};
\node[roundnode] (uppercircle) [above=of midcircle] {1};
\node[roundnode] (rightcircle) [right=of midcircle] {4};
\node[roundnode] (lowercircle) [below=of midcircle] {3};
%Edges out of 1
\draw[->] (uppercircle.east) to[bend left=20] node[above right]{-}(rightcircle.north);
\draw[->] (uppercircle.-135) to[bend right=40] node[right]{-}(lowercircle.135);
\draw[->] (uppercircle.135) to[out=135,in=180] ($(uppercircle) +(0,3em)$)node[above]{+} to[out=0, in =45] (uppercircle.45);
%2 Edges out of 2
\draw[->] (midcircle.east) --node[above]{+} (rightcircle.west);
\draw[->] (midcircle.80) to[out=80,in=135] ($(midcircle) +(2em,2em)$)node[right]{+} to[out=-45, in =10] (midcircle.10);
\draw[->] (midcircle.south) -- (lowercircle.north);
\draw[->] (midcircle.north) -- (uppercircle.south);
%Edges out of 3
\draw[->] (lowercircle.150) to[bend left=80]node[left]{+}(uppercircle.-150);
\draw[->] (lowercircle.east) to[bend right=20]node[below right]{-}(rightcircle.south);
\draw[->] (lowercircle.-135) to[out=-135,in=180] ($(lowercircle) +(0,-3em)$)node[below]{+} to[out=0, in =-45](lowercircle.-45);
%Edges out of 4
\draw[->] (rightcircle.-135) to[bend left=20] node[below]{-} (midcircle.-45);
\end{tikzpicture}
\end{figure}
\end{document}