Tikz에서 다중 규모 네트워크 그리기

Tikz에서 다중 규모 네트워크 그리기

저는 이 기간에 TikZ를 배우고 있지만 논문을 위한 일부 네트워크를 그리는 데 몇 가지 문제가 있습니다. TikZ에서 다음과 유사하게 보이는 네트워크를 그리려고 합니다.this picture:

여기에 이미지 설명을 입력하세요

다음 코드를 작성했습니다.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary[topaths]
\newcount\mycount
\begin{document}
\begin{tikzpicture}[transform shape]
  \foreach \x in {1,...,8}{
    \pgfmathparse{(\x-1)*45+floor(\x/9)*22.5}
    \node[draw,circle,inner sep=0.25cm] (N-\x) at (\pgfmathresult:5.4cm) {};
  }

  \foreach \x [count=\xi from 1] in {1,...,8}{
    \foreach \y in {\x,...,8}{
    \path (N-\xi) edge[-] (N-\y);
  }
}
\end{tikzpicture}
\end{document}

이미지의 파벌 중 하나만 그립니다. 그림에 표시된 전체 네트워크를 그리는 데 도움을 주실 수 있나요?

감사합니다.

답변1

이 명령은 \MyFive기본 그림을 그리고 첫 번째 인수의 문자열과 \x첫 번째 카운터를 사용하여 해당 노드에 이름을 할당합니다 \foreach(예를 들어 \MyFive{A}그림을 그리고 해당 노드의 이름을 A-1, A-2,..., A-8). 그런 다음 scopes를 사용하여 기본 수치를 이동하고 \draw작업을 통해 선을 그립니다.

\documentclass[border=3pt]{standalone}
\usepackage{tikz}
\usetikzlibrary[topaths]

\newcommand\MyFive[1]{%
  \foreach \x in {1,...,8}{
    \pgfmathparse{(\x-1)*45+floor(\x/9)*22.5}
    \node[draw,circle,inner sep=2pt] (#1-\x) at (\pgfmathresult:1.5cm) {};
  }

  \foreach \x [count=\xi from 1] in {1,...,8}{
    \foreach \y in {\x,...,8}{
    \path (#1-\xi) edge[-] (#1-\y);
  }
}
}

\begin{document}

\begin{tikzpicture}
\MyFive{A}
\begin{scope}[xshift=4.5cm]
\MyFive{B}
\end{scope}
\begin{scope}[xshift=9cm]
\MyFive{C}
\end{scope}
\begin{scope}[xshift=13.5cm]
\MyFive{D}
\end{scope}

\begin{scope}[yshift=-4.5cm]
\MyFive{E}
\end{scope}
\begin{scope}[xshift=4.5cm,yshift=-4.5cm]
\MyFive{F}
\end{scope}
\begin{scope}[xshift=9cm,yshift=-4.5cm]
\MyFive{G}
\end{scope}
\begin{scope}[xshift=13.5cm,yshift=-4.5cm]
\MyFive{H}
\end{scope}

\begin{scope}[yshift=-9cm]
\MyFive{I}
\end{scope}
\begin{scope}[xshift=4.5cm,yshift=-9cm]
\MyFive{J}
\end{scope}
\begin{scope}[xshift=9cm,yshift=-9cm]
\MyFive{K}
\end{scope}
\begin{scope}[xshift=13.5cm,yshift=-9cm]
\MyFive{L}
\end{scope}

\begin{scope}[yshift=-13.5cm]
\MyFive{M}
\end{scope}
\begin{scope}[xshift=4.5cm,yshift=-13.5cm]
\MyFive{N}
\end{scope}
\begin{scope}[xshift=9cm,yshift=-13.5cm]
\MyFive{O}
\end{scope}
\begin{scope}[xshift=13.5cm,yshift=-13.5cm]
\MyFive{P}
\end{scope}

\draw (A-7) -- (E-3);
\draw (A-8) -- (F-4);
\draw (A-1) -- (B-5);
\draw (E-2) -- (B-6);
\draw (E-1) -- (F-5);
\draw (B-7) -- (F-3);

\draw (C-7) -- (G-3);
\draw (C-8) -- (H-4);
\draw (C-1) -- (D-5);
\draw (G-2) -- (D-6);
\draw (G-1) -- (H-5);
\draw (D-7) -- (H-3);

\draw (I-7) -- (M-3);
\draw (I-8) -- (N-4);
\draw (I-1) -- (J-5);
\draw (M-2) -- (J-6);
\draw (M-1) -- (N-5);
\draw (J-7) -- (N-3);

\draw (K-7) -- (O-3);
\draw (K-8) -- (P-4);
\draw (K-1) -- (L-5);
\draw (O-2) -- (L-6);
\draw (O-1) -- (P-5);
\draw (L-7) -- (P-3);

\draw (F-8) -- (K-4);
\draw (G-6) -- (J-2);
\end{tikzpicture}

\end{document}

여기에 이미지 설명을 입력하세요

\foreach추가 루프를 사용할 수 있도록 기본 그림에 대해 다른 이름을 선택하면 코드가 크게 단순화될 수 있습니다 . 그러나 나는 여기서 간결함보다 명확성을 선호합니다.

답변2

명확성보다 간결성을 추구하고 여러 문장 pic의 기능을 활용합니다.PGF 3.0foreach

\documentclass[tikz,border=5]{standalone}
\tikzset{pics/clique/.style={
  code={
    \foreach \i in {1,...,8}
      \node [circle, draw] (n-#1-\i) at (\i*45-45:2) {};
    \foreach \i [evaluate={\k=int(\i+1);}] in {1,...,7}
      \foreach \j in {\k,...,8}
        \draw (n-#1-\i) -- (n-#1-\j);
  }
}}
\begin{document}
\begin{tikzpicture}
\foreach \x in {1,...,4}
  \foreach \y in {1,...,4}
    \path (\x*6,\y*6) pic {clique={\x-\y}};    
\draw \foreach \a/\b [evaluate={\c=int(\a+1); \d=int(\b+1);}] in {1/1, 3/1, 1/3, 3/3}{ 
    (n-\a-\b-2) -- (n-\c-\d-6) (n-\a-\b-3) -- (n-\a-\d-7)
    (n-\a-\b-1) -- (n-\c-\b-5) (n-\c-\b-3) -- (n-\c-\d-7)
    (n-\c-\b-4) -- (n-\a-\d-8) (n-\a-\d-1) -- (n-\c-\d-5)
  }
  (n-2-2-2) -- (n-3-3-6) (n-3-2-4) -- (n-2-3-8);
\end{tikzpicture}
\end{document} 

여기에 이미지 설명을 입력하세요

답변3

matrix nodefrom 를 통한 또 다른 시도 tikzlibrary. 먼저 기본 tikz 이미지를 빨간색과 검정색의 \single두 개의 연결 선 스타일 로 정의한 다음 모든 이미지를 행렬 노드에 넣습니다. 그 사이의 규칙성을 찾아 연결선을 그리고 루프를 통해 이루어집니다.lineSlineLforeach

여기에 이미지 설명을 입력하세요

암호

\documentclass[border=3pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{topaths,matrix}
\begin{document}

\def\single{
\begin{tikzpicture}[scale=0.3]
\foreach \x in {1,...,8}{
    \pgfmathparse{(\x-1)*45+floor(\x/9)*22.5}
    \node[draw,circle,inner sep=0.25cm] (N-\x) at (\pgfmathresult:5.4cm) {};
  }
  \foreach \x [count=\xi from 1] in {1,...,8}{
    \foreach \y in {\x,...,8}{
    \path (N-\xi) edge[-] (N-\y);
  }
}
\end{tikzpicture}
}
\tikzset{
lineL/.style={draw, shorten >=-29pt,shorten <=-29pt,},
lineS/.style={draw, red, shorten >=-4pt,shorten <=-4pt}
}

\begin{tikzpicture}[auto]
% Place nodes with matrix nodes
 \matrix[matrix of nodes, column sep=1cm, row sep=1cm]{%
    \node [] (A) {\single};  & \node [] (B) {\single};  & \node [] (C) {\single};  &       \node [] (D) {\single};\\
    \node [] (A1) {\single}; & \node [] (B1) {\single}; & \node [] (C1) {\single}; &       \node [] (D1) {\single};\\
    \node [] (A2) {\single}; & \node [] (B2) {\single}; & \node [] (C2) {\single}; &       \node [] (D2) {\single};\\
    \node [] (A3) {\single}; & \node [] (B3) {\single}; & \node [] (C3) {\single}; &       \node [] (D3) {\single};\\
};
% Draw edges
    \foreach \c in{A,B,C,D}{
    \foreach \f/\t in {{}/1,2/3}
{
    \path [lineS] (\c\f) -- (\c\t); 
}
};
  \foreach \c/\d in{A/B,C/D,A1/B1/,C1/D1,A2/B2,C2/D2,A3/B3/,C3/D3}{
    \path [lineS] (\c.0) -- (\d.180);
};

\foreach \f/\t in {A/B1,C/D1,B1/C2,A2/B3,C2/D3}
{
    \path [lineL] (\f.-45) -- (\t.135) ; 
};
\foreach \f/\t in {B/A1,D/C1,C1/B2,B2/A3,D2/C3}
{
    \path [lineL] (\f.-135) -- (\t.45) ; 
};
\end{tikzpicture}
\end{document}

관련 정보