Tikz: Tikz를 사용한 블록 다이어그램

Tikz: Tikz를 사용한 블록 다이어그램

저는 latex와 tikz를 처음 접했고 그것을 사용하여 블록 다이어그램을 그리고 싶었습니다. 하지만 몇 가지 문제가 있습니다. 제가 가지고 있는 몇 가지 질문에 대해 누군가 도움을 줄 수 있나요?

  1. 채워진 상자 중앙에 있고 text0과 text 6에 대한 상자가 없도록 '이 텍스트'를 작성하는 방법은 무엇입니까?

  2. 상자 사이나 화살표 위에 텍스트를 쓰는 방법은 무엇입니까?

  3. 개별 상자의 크기를 제어하고 화살표 모양을 다르게 할 수 있는 방법이 있나요?

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\usepackage{tikz}

\usetikzlibrary{shapes,arrows,positioning,fit,backgrounds}
\tikzstyle{block} = [draw, rectangle,  align=center, text width=2.4cm, text centered, minimum height=1.2cm, node distance=3.5cm,fill=white]
\tikzstyle{container} = [draw, rectangle, inner sep=0.3cm, fill=gray,minimum height=3cm]

\def\bottom#1#2{\hbox{\vbox to #1{\vfill\hbox{#2}}}}
\tikzset{
  mybackground/.style={execute at end picture={
      \begin{scope}[on background layer]
        \node[] at (current bounding box.north){\bottom{1cm} #1};
        \end{scope}
    }},
}
\begin{document}


\resizebox{14cm}{3cm}{%
\begin{tikzpicture}[>=latex',mybackground={This text}]
    \node [block, name= text0] (text0){text0};
    \node [block, right of=text0](text1) {text1};
    \node [block, right of=text1] (text2) {text2};
    \node [block, right of=text2] (text3) {text3};
    \node [block, right of=text3] (text4) {text4};
    \node [block, right of=text4] (text5) {text5};
     \node [block, right of=text5] (text6) {text6};
    \begin{scope}[on background layer]
    \node [container,fit= (text3) (text4)] (container) {};
     \end{scope}
    \draw [->] (text0) -- (text1);
    \draw [->] (text1) -- (text2);
    \draw [->] (text2) -- node {}(text3);
    \draw [->] (text3) -- node {}(text4);
    \draw [->] (text4) -- node {} (text5);
    \draw [->] (text5) -- node {} (text6);

\end{tikzpicture}

}


\end{document}

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

답변1

아래 예가 귀하의 모든 요청을 충족시키기를 바랍니다.

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

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                backgrounds,
                chains,
                fit,
                quotes}

\begin{document}
    \begin{tikzpicture}[auto,
    node distance = 15mm,
        start chain = A going right,
     block/.style = {draw, fill=white,
                     text width=#1, minimum height=12mm, align=center,
                     outer sep=0pt, on chain},
     block/.default = 18mm,
 container/.style = {draw, fill=gray!50,
                     inner xsep=2mm, inner ysep=7mm},
                        ]
\node   [block] {text 0};    % block name is A-1
\node   [block] {text 1};
\node   [block] {text 2};
\node   [block=22mm] {text 3};    % block name is A-4
\node   [block=11mm] {text 4};    % block name is A-5
\node   [block] {text 5};
\node   [block] {text 6};    % block name is A-7
%
\scoped[on background layer]
    \node [container, label={[anchor=north]This text},
           fit= (A-4) (A-5)] (container) {};
\draw [-Stealth]
    (A-1) edge ["text 1"] (A-2)    % text on arrow is between " and "
    (A-2) edge ["text 2"] (A-3)
    (A-3) edge ["text 3"] (A-4)
    (A-4) edge ["text 4"] (A-5)
    (A-5) edge ["text 5"] (A-6)
    (A-6) edge ["text 5"] (A-7);
    \end{tikzpicture}
\end{document}
  • 귀하의 블록 다이어그램은 간단하고 모든 블록이 체인에 있으므로 위치 지정을 위해 라이브러리를 사용하는 것이 좋습니다 chains(사이의 거리가 동일하다고 가정하지만 일부가 다른 경우 로컬 사용으로 변경할 수 있음).right=of <name previous block>
  • 블록 사이의 화살표에 대한 텍스트는 quotes다음과 같이 라이브러리의 도움으로 간단하게 작성할 수 있습니다.(<node name i>) edge [" your text"] (<node name i+1>)
  • 첫 번째 질문을 이해하지 못했습니다. 죄송합니다!!
  • 사용하지 마세요 \resizebox! 이미지가 나빠지는 원인이 됩니다. 오히려 블록 크기, 글꼴 및 블록 사이의 거리를 조정합니다.
  • 를 사용하면 arrows.meta화살촉 크기(길이, 너비, 각도 등)를 간단히 조정할 수 있습니다. 자세한 내용은 "tikz & pgf 매뉴얼, v 3.0.1a", 섹션 "16.5 참조: 화살표 팁", 페이지 201을 참조하십시오. 아래 mwe에서는 기본값을 사용하지만 예를 들어 실험해 볼 수 있습니다(언급된 매뉴얼의 209페이지 참조). :

\draw[-{Stealth[length=2mm,width=3mm,inset=0.5mm]}] ...

관련 정보