tikz 및 노드 그리기

Sep 27 2020

6 개의 노드를 더 추가하여이 "노드"예제를 확장하고 싶지만이 샘플 코드의 논리를 볼 수 없습니다. 나는 (a), (b), (c)의 관계와 그것들이 실제로 어떻게 사용되는지 알 수 없었습니다. 누군가 나에게 이것을 설명 할 수 있습니까? 다음은 출력 링크입니다.https://texample.net/tikz/examples/nav1d/

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\pagestyle{empty}
%
\tikzstyle{int}=[draw, fill=blue!20, minimum size=2em]
\tikzstyle{init} = [pin edge={to-,thin,black}]

\begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
    \node [int, pin={[init]above:$v_0$}] (a) {$\frac{1}{s}$};
    \node (b) [left of=a,node distance=2cm, coordinate] {a};
    \node [int, pin={[init]above:$p_0$}] (c) [right of=a] {$\frac{1}{s}$};
    \node [coordinate] (end) [right of=c, node distance=2cm]{};
    \path[->] (b) edge node {$a$} (a);
    \path[->] (a) edge node {$v$} (c);
    \draw[->] (c) edge node {$p$} (end) ;
\end{tikzpicture}

\end{document}

답변

2 Zarko Sep 27 2020 at 13:15
  • 귀하의 질문은 완전히 명확하지 않습니다 ...
  • 사용 된 예제는 다소 오래되어 결과적으로 사용되지 않는 구문 ( tikzstyle대신 tikzset등)을 사용합니다.
  • 모든 노드가 체인에 있고 chains라이브러리를 사용하여 그릴 수있는 것보다 크기와 내용이 같다고 가정하고, 모서리 사용 quotes라이브러리의 레이블 과 모든 모서리 및 핀에 대한 스타일 정의 :
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                chains,
                positioning,
                quotes}

\begin{document}
    \begin{tikzpicture}[
node distance = 12mm,
  start chain = going right, 
   int/.style = {draw, fill=blue!20, minimum size=2em, font=\large, 
                 on chain},
 every edge/.style = {draw, -Latex},
every edge quotes/.style = {auto, font=\footnotesize, text depth=0.25ex},
  every pin/.style = {pin edge={Latex-,thin,black}, font=\footnotesize}
                        ]
% nodes vith pin above
\coordinate[on chain] (in);
\node (a) [int, pin=$v_0$] {$\frac{1}{s}$};
\node (b) [int, pin=$p_0$] {$\frac{1}{s}$};
\node (c) [int, pin=$p_1$] {$\frac{1}{s}$};
\node (d) [int, pin=$p_2$] {$\frac{1}{s}$};
\node (e) [int, pin=$p_3$] {$\frac{1}{s}$};
\coordinate[on chain] (out);
% connection between nodes
\draw   (in)    edge ["$a$"] (a) 
        (a)     edge ["$v$"] (b) 
        (b)     edge ["$p$"] (c)
        (c)     edge ["$p_1$"] (d)
        (d)     edge ["$p_2$"] (e)
        (e)     edge ["$p_3$"] (out) ;
    \end{tikzpicture}
\end{document}

더 많은 노드를 체인에 추가하려면 이미 존재하는 노드에 추가하십시오. 시작 조건이 필요하지 않으면 간단히 드롭하십시오 pin.

편집 : 제공 하는 예제는 두 부분으로 구성됩니다.

  • 스타일 정의 (사용되지 않는 구문이 사용되는 곳, 오늘은 다음과 같이 작성해야합니다.
\tikzset{
  int/.style = {draw, fill=blue!20, minimum size=2em},
 init/.style = {pin edge={to-,thin,black}}
         }

또는 옵션 tikzpicture:

\begin{tikzpicture}[node distance=2.5cm,auto,>=latex',
 int/.style = {draw, fill=blue!20, minimum size=2em},
init/.style = {pin edge={to-,thin,black}}
               ]
  • 이미지에 원하는 것을 그리는 이미지 본문. 이것은 여러 가지 방법으로 할 수 있습니다. 예를 들면
    • 절대 위치 od 노드 사용 :
\node (<name>) [<style>] at (<x coordinate>,<y coordinate>) {<node content>};
  • 노드의 상대 위치 지정 사용 :
\node (<name 1>) [<style 1>] at (<x coordinate>,<y coordinate>) {<node content>};
\node (<name 2>) [<style 2>, above right=of <name 1>]  {<node content>};

여기서, <node 2>상기 위치 노드로부터 왼쪽한다 <node 2>선언 노드 거리 tikzset또는 옵션으로서 보여 상기 예에서 수행한다.

  • 그릴 수있는 선
\draw[<option>] (<coordinate 1>) -- (<coordinate 2>);

어디를 위해 <option>당신은 예를 들어 사용할 수있는 init질문과 좌표가 노드의 이름을 사용하기위한 보였다 MWE (최소 작업 예)에서 수행한다.

또는 내 대답에 사용되는 고급 접근 방식을 사용하십시오.

  • 다른 옵션의 경우 TikZ 패키지 및 해당 라이브러리에 더 익숙해 져야합니다. 매뉴얼은 LaTeX 설치의 일부이거나 CTAN에서 찾을 수 있습니다 ( tikz.sty 는 google 사용 ).
  • Manula는 거대하므로 시작하려면 파트 I 튜토리얼 및 지침을 읽고 파트 III 보다 : TikZ ist kein Zeichenprogramm .
  • 이미지를 그리는 데 갇 히면 여기에서 구체적인 도움을 요청하십시오. 이 때 사람들이 쉽게 도울 수 있도록 문제를 재현하는 MWE를 제공하십시오 (MWE 준비, 내 대답에 예제가 있으며 여러 번 스스로 해결책을 찾거나 코드 오류를 발견하는 데 도움이 됨)
  • 사이트는 tikz패키지 사용 방법에 대한 일반적인 지침을 제공하기위한 것이 아닙니다 .
2 jsbibra Sep 27 2020 at 08:01

전체 설명은 다음과 같습니다.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary {arrows.meta,graphs,shapes.misc}
\usetikzlibrary{arrows}
\begin{document}
    \pagestyle{empty}
    %no headers and footers just a blank page
    \tikzstyle{int}=[draw, fill=blue!20, minimum size=2em]
    %macro for (draw)ing square, (fill) inside color blue, default size 2em
    \tikzstyle{init} = [pin edge={to-,thin,black}]
    %macro for arrows/ edges
    
    \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
        %separation between nodes 2.5cm, type of arrows defined with >=latex
        \node [int, pin={[init]above:$v_0$}] (a) {$\frac{1}{s}$};
        %call the int macro for square named (a), and the init macro for the arrow 
        pointing (to-a), label above the arrow is v_0, and text inside the named node 
        is  {$\frac{1}{s}$}
        \node (b) [left of=a,node distance=2cm, coordinate] {a};
        %node named (b) placed left of node named (a), tec=xt inside the node is {a}
        \node [int, pin={[init]above:$p_0$}] (c) [right of=a] {$\frac{1}{s}$};
        %same as first node named (a)
        \node [coordinate] (end) [right of=c, node distance=2cm]{};
        %same as node named (end) after node named (c)
        \path[->] (b) edge node {$a$} (a);
        %draw an arrow from node b to node a, label above the arrow  {$a$}
        \path[->] (a) edge node {$v$} (c);
        %same as arrow above
        \draw[->] (c) edge node {$p$} (end) ;
        %same as arrow above
    \end{tikzpicture}
\end{document}