如何为使用 tikz 绘制的图形添加虚线和标题?

如何为使用 tikz 绘制的图形添加虚线和标题?

我想将虚线添加到使用 tikz 绘制的流程图中。当前的工作如下所示:

\documentclass{article}

\usepackage{tikz-cd,tikz}
\usetikzlibrary{arrows, matrix, positioning, shapes, arrows, decorations.pathreplacing}
\usetikzlibrary{shapes.geometric, arrows, calc, intersections}

\begin{document}
    \tikzstyle{decision} = [diamond, draw, fill=blue!20, 
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
    \tikzstyle{block} = [rectangle, draw, fill=green!10, 
    text width=25em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block2} = [rectangle, draw, fill=lime!35, 
    text width=12em, text centered, rounded corners, minimum height=3em]
    \tikzstyle{block3} = [rectangle, draw, fill=black!10!green, 
    text width=12em, text centered, rounded corners, minimum height=3em]
    \tikzstyle{block4} = [rectangle, draw, fill=black!10!green, 
    text width=8em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block5} = [rectangle, draw, fill=black!10!green, 
    text width=5em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block6} = [rectangle, draw, fill=black!10!green, 
    text width=5em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block7} = [rectangle, draw, fill=black!10!green, 
    text width=13em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block8} = [rectangle, draw, fill=black!10!green, 
    text width=6em, text centered, ellipse, minimum height=4em]
    \tikzstyle{block9} = [rectangle, draw, fill=teal!60, 
    text width=15em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block10} = [rectangle, draw, fill=cyan!60, 
    text width=10em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block11} = [rectangle, draw, fill=white!60, 
    text width=10em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block12} = [rectangle, draw, fill=cyan!60, 
    text width=15em, text centered, rounded corners, minimum height=3em]
    \tikzstyle{block13} = [rectangle, draw, fill=cyan!30, 
    text width=20em, text centered, rounded corners, minimum height=3em]
    \tikzstyle{line} = [draw, -latex']
    \tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=2cm,
    minimum height=4em]
    \vspace{1cm}

    \begin{figure}[!h]
        \centering
        \begin{tikzpicture}[node distance = 2cm, auto]
        % Place nodes
        \node [block] (title) {\textbf{JORDAN-CHEVALLEY DECOMPOSITION FOR\\ EEG SIGNALS DURING EPILEPTIC SEIZURES}};
        \node [block2, below of=title, node distance=2.3cm] (chap1) {\textbf{Chapter 1}\\ Introduction};
        \node [block3, below of=chap1, node distance=2.3cm] (chap2) {\textbf{Chapter 2}\\ Epileptic seizure};
        \node [block4, below of=chap2, node distance=2.3cm] (patient) {Patient and EEG signals recording};
        \node [block5, left of=patient, node distance=4cm] (fttm) {FTTM};
        \node [block6, right of=patient, node distance=4cm](flateeg) {Flat EEG};
        \node [block7, below of=patient, node distance=2.5cm](KR) {Krohn-Rhodes decomposition of EEG signals};
        \node [block8, below of=KR, node distance=2.5cm](JC) {Jordan-Chevalley decomposition};
        \node[block8, left of=JC, node distance=5cm](matrix) {Matrix partial order};
        \node[block8, right of=JC, node distance=5cm](prime) {Additive of prime number theory};
        \node[block9, below of=JC, node distance=2.8cm](chap3) {\textbf{Chapter 3}\\ Ordering of matrices by precede operator};
        \node [block9, below of=fttm, node distance =10cm](partial) {\textbf{Chapter 4}\\ Jordan-Chevalley decomposition of elementary EEG signals};
        \node [block9, below of=flateeg, node distance=10cm](chap5) {\textbf{Chapter 5}\\ Pseudo-Goldbach Theorem};
        \node[block12, below of=chap3, node distance=4.5cm](chap6) {\textbf{Chapter 6}\\ Implementation};
        \node[block13, below of=chap6, node distance=2.3cm](chap7) {\textbf{Chapter 7}\\ Conclusion and Recommendation};

        Draw edges
        \path [line] (title) -- (chap1);
        \path [line] (chap1) -- (chap2);
        \path [line] (chap2) -- (patient);
        \path [line] (patient) -- (fttm);
        \path [line] (patient) -- (flateeg);
        \path [line] (fttm) |-  (KR);
        \path [line] (flateeg) |-  (KR);
        \path [line] (KR) -- (JC);
        \path [line] (JC) -- (matrix);
        \path [line] (JC) -- (prime);
        \path [line] (JC) -- (chap3);
        \path [line] (chap3) -| (partial);
        \path [line] (chap3) -| (chap5);
        \path [line] (partial) -- (chap5);
        \path [line] (chap3) -- (chap6);
        \path [line] (chap6) -- (chap7);
        \end{tikzpicture}
        \caption{Research framework}
        \label{fig:overview}
    \end{figure}
\end{document}

产生:

在此处输入图片描述

我想在这个图上添加虚线和标题,如下所示:

在此处输入图片描述

请帮忙。

答案1

这是一个起点。使用您已经创建的节点,在它们之间的中点定义新坐标。我使用了southnorth

然后,从左到右绘制虚线,改变值xshift。我使用了\pm 7cm

在此处输入图片描述

平均能量损失

\documentclass{article}

\usepackage{tikz-cd,tikz}
\usetikzlibrary{arrows, matrix, positioning, shapes, arrows, decorations.pathreplacing,calc}
\usetikzlibrary{shapes.geometric, arrows, calc, intersections}

\begin{document}
    \tikzstyle{decision} = [diamond, draw, fill=blue!20, 
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
    \tikzstyle{block} = [rectangle, draw, fill=green!10, 
    text width=25em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block2} = [rectangle, draw, fill=lime!35, 
    text width=12em, text centered, rounded corners, minimum height=3em]
    \tikzstyle{block3} = [rectangle, draw, fill=black!10!green, 
    text width=12em, text centered, rounded corners, minimum height=3em]
    \tikzstyle{block4} = [rectangle, draw, fill=black!10!green, 
    text width=8em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block5} = [rectangle, draw, fill=black!10!green, 
    text width=5em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block6} = [rectangle, draw, fill=black!10!green, 
    text width=5em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block7} = [rectangle, draw, fill=black!10!green, 
    text width=13em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block8} = [rectangle, draw, fill=black!10!green, 
    text width=6em, text centered, ellipse, minimum height=4em]
    \tikzstyle{block9} = [rectangle, draw, fill=teal!60, 
    text width=15em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block10} = [rectangle, draw, fill=cyan!60, 
    text width=10em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block11} = [rectangle, draw, fill=white!60, 
    text width=10em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block12} = [rectangle, draw, fill=cyan!60, 
    text width=15em, text centered, rounded corners, minimum height=3em]
    \tikzstyle{block13} = [rectangle, draw, fill=cyan!30, 
    text width=20em, text centered, rounded corners, minimum height=3em]
    \tikzstyle{line} = [draw, -latex']
    \tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=2cm,
    minimum height=4em]
    \vspace{1cm}

    \begin{figure}[!h]
        \centering
        \begin{tikzpicture}[node distance = 2cm, auto]
        % Place nodes
        \node [block] (title) {\textbf{JORDAN-CHEVALLEY DECOMPOSITION FOR\\ EEG SIGNALS DURING EPILEPTIC SEIZURES}};
        \node [block2, below of=title, node distance=2.3cm] (chap1) {\textbf{Chapter 1}\\ Introduction};
        \node [block3, below of=chap1, node distance=2.3cm] (chap2) {\textbf{Chapter 2}\\ Epileptic seizure};
        \node [block4, below of=chap2, node distance=2.3cm] (patient) {Patient and EEG signals recording};
        \node [block5, left of=patient, node distance=4cm] (fttm) {FTTM};
        \node [block6, right of=patient, node distance=4cm](flateeg) {Flat EEG};
        \node [block7, below of=patient, node distance=2.5cm](KR) {Krohn-Rhodes decomposition of EEG signals};
        \node [block8, below of=KR, node distance=2.5cm](JC) {Jordan-Chevalley decomposition};
        \node[block8, left of=JC, node distance=5cm](matrix) {Matrix partial order};
        \node[block8, right of=JC, node distance=5cm](prime) {Additive of prime number theory};
        \node[block9, below of=JC, node distance=2.8cm](chap3) {\textbf{Chapter 3}\\ Ordering of matrices by precede operator};
        \node [block9, below of=fttm, node distance =10cm](partial) {\textbf{Chapter 4}\\ Jordan-Chevalley decomposition of elementary EEG signals};
        \node [block9, below of=flateeg, node distance=10cm](chap5) {\textbf{Chapter 5}\\ Pseudo-Goldbach Theorem};
        \node[block12, below of=chap3, node distance=4.5cm](chap6) {\textbf{Chapter 6}\\ Implementation};
        \node[block13, below of=chap6, node distance=2.3cm](chap7) {\textbf{Chapter 7}\\ Conclusion and Recommendation};

        Draw edges
        \path [line] (title) -- (chap1);
        \path [line] (chap1) -- (chap2);
        \path [line] (chap2) -- (patient);
        \path [line] (patient) -- (fttm);
        \path [line] (patient) -- (flateeg);
        \path [line] (fttm) |-  (KR);
        \path [line] (flateeg) |-  (KR);
        \path [line] (KR) -- (JC);
        \path [line] (JC) -- (matrix);
        \path [line] (JC) -- (prime);
        \path [line] (JC) -- (chap3);
        \path [line] (chap3) -| (partial);
        \path [line] (chap3) -| (chap5);
        \path [line] (partial) -- (chap5);
        \path [line] (chap3) -- (chap6);
        \path [line] (chap6) -- (chap7);

\coordinate (tmp1) at ($ (title.south)!.5!(chap1.north) $);
\draw[dashed] ([xshift=-7cm]tmp1)node[below right]{Introduction} -- ([xshift=7cm]tmp1);

\coordinate (tmp2) at ($ (chap1.south)!.5!(chap2.north) $);
\draw[dashed] ([xshift=-7cm]tmp2)node[below right]{Literature Review} -- ([xshift=7cm]tmp2);

\coordinate (tmp3) at ($ (JC.south)!.5!(chap3.north) $);
\draw[dashed] ([xshift=-7cm]tmp3)node[below right,align=left]{Main Results and\\ Implementation} -- ([xshift=7cm]tmp3);

\coordinate (tmp4) at ($ (chap6.south)!.5!(chap7.north) $);
\draw[dashed] ([xshift=-7cm]tmp4)node[below right]{Conclusion} -- ([xshift=7cm]tmp4);

        \end{tikzpicture}
        \caption{Research framework}
        \label{fig:overview}
    \end{figure}
\end{document}

答案2

此版本使用coordinate[midway]和来(current bounding box)放置虚线。

\documentclass{article}

\usepackage{tikz-cd,tikz}
\usetikzlibrary{arrows, matrix, positioning, shapes, arrows, decorations.pathreplacing}
\usetikzlibrary{shapes.geometric, arrows, calc, intersections}

\begin{document}
    \tikzstyle{decision} = [diamond, draw, fill=blue!20, 
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
    \tikzstyle{block} = [rectangle, draw, fill=green!10, 
    text width=25em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block2} = [rectangle, draw, fill=lime!35, 
    text width=12em, text centered, rounded corners, minimum height=3em]
    \tikzstyle{block3} = [rectangle, draw, fill=black!10!green, 
    text width=12em, text centered, rounded corners, minimum height=3em]
    \tikzstyle{block4} = [rectangle, draw, fill=black!10!green, 
    text width=8em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block5} = [rectangle, draw, fill=black!10!green, 
    text width=5em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block6} = [rectangle, draw, fill=black!10!green, 
    text width=5em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block7} = [rectangle, draw, fill=black!10!green, 
    text width=13em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block8} = [rectangle, draw, fill=black!10!green, 
    text width=6em, text centered, ellipse, minimum height=4em]
    \tikzstyle{block9} = [rectangle, draw, fill=teal!60, 
    text width=15em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block10} = [rectangle, draw, fill=cyan!60, 
    text width=10em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block11} = [rectangle, draw, fill=white!60, 
    text width=10em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block12} = [rectangle, draw, fill=cyan!60, 
    text width=15em, text centered, rounded corners, minimum height=3em]
    \tikzstyle{block13} = [rectangle, draw, fill=cyan!30, 
    text width=20em, text centered, rounded corners, minimum height=3em]
    \tikzstyle{line} = [draw, -latex']
    \tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=2cm,
    minimum height=4em]
    \vspace{1cm}

    \begin{figure}[!h]
        \centering
        \begin{tikzpicture}[node distance = 2cm, auto]
        % Place nodes
        \node [block] (title) {\textbf{JORDAN-CHEVALLEY DECOMPOSITION FOR\\ EEG SIGNALS DURING EPILEPTIC SEIZURES}};
        \node [block2, below of=title, node distance=2.3cm] (chap1) {\textbf{Chapter 1}\\ Introduction};
        \node [block3, below of=chap1, node distance=2.3cm] (chap2) {\textbf{Chapter 2}\\ Epileptic seizure};
        \node [block4, below of=chap2, node distance=2.3cm] (patient) {Patient and EEG signals recording};
        \node [block5, left of=patient, node distance=4cm] (fttm) {FTTM};
        \node [block6, right of=patient, node distance=4cm](flateeg) {Flat EEG};
        \node [block7, below of=patient, node distance=2.5cm](KR) {Krohn-Rhodes decomposition of EEG signals};
        \node [block8, below of=KR, node distance=2.5cm](JC) {Jordan-Chevalley decomposition};
        \node[block8, left of=JC, node distance=5cm](matrix) {Matrix partial order};
        \node[block8, right of=JC, node distance=5cm](prime) {Additive of prime number theory};
        \node[block9, below of=JC, node distance=2.8cm](chap3) {\textbf{Chapter 3}\\ Ordering of matrices by precede operator};
        \node [block9, below of=fttm, node distance =10cm](partial) {\textbf{Chapter 4}\\ Jordan-Chevalley decomposition of elementary EEG signals};
        \node [block9, below of=flateeg, node distance=10cm](chap5) {\textbf{Chapter 5}\\ Pseudo-Goldbach Theorem};
        \node[block12, below of=chap3, node distance=4.5cm](chap6) {\textbf{Chapter 6}\\ Implementation};
        \node[block13, below of=chap6, node distance=2.3cm](chap7) {\textbf{Chapter 7}\\ Conclusion and Recommendation};

        %Draw edges
        \path [line] (title) -- (chap1) coordinate[midway] (A);
        \path [line] (chap1) -- (chap2) coordinate[midway] (B);
        \path [line] (chap2) -- (patient);
        \path [line] (patient) -- (fttm);
        \path [line] (patient) -- (flateeg);
        \path [line] (fttm) |-  (KR);
        \path [line] (flateeg) |-  (KR);
        \path [line] (KR) -- (JC);
        \path [line] (JC) -- (matrix);
        \path [line] (JC) -- (prime);
        \path [line] (JC) -- (chap3) coordinate[midway] (C);
        \path [line] (chap3) -| (partial);
        \path [line] (chap3) -| (chap5);
        \path [line] (partial) -- (chap5);
        \path [line] (chap3) -- (chap6);
        \path [line] (chap6) -- (chap7) coordinate[midway] (D);

        %Draw dashed lines (use previously defined bounding box)
        \draw[dashed] (current bounding box.west |- A) -- (current bounding box.east |- A) 
          node[pos=0, below right] {Introduction};
        \draw[dashed] (current bounding box.west |- B) -- (current bounding box.east |- B)
          node[pos=0, below right] {Literature Review};
        \draw[dashed] (current bounding box.west |- C) -- (current bounding box.east |- C)
          node[pos=0, below right, align=left] {Main results and \\ implementation};
        \draw[dashed] (current bounding box.west |- D) -- (current bounding box.east |- D)
          node[pos=0, below right] {Conclusion};
        \end{tikzpicture}
        \caption{Research framework}
        \label{fig:overview}
    \end{figure}
\end{document}

答案3

在此处输入图片描述 对于虚线

操作部分如下 - 只需定义两个节点来定义虚线的起点和终点 - 然后使用命令\draw连接两个节点

要垂直向上或向下移动线条,请使用\yshift和 进行水平移动或更改线条的长度,请改变\xshift

    \node[left of=JC, xshift=6cm, yshift=1cm](m) {};
    \node[right of=JC, xshift=-6cm, yshift=1cm](p) {};
    \draw [thick,dash dot] (m) -- (p);

要在虚线上方添加简介标题,请添加代码

    \node[left of=JC, xshift=5.2cm, yshift=1.2cm](m) {Introduction};  

在此处输入图片描述

完整的 MWE

\documentclass{article}

\usepackage{tikz-cd,tikz}
\usetikzlibrary{arrows, matrix, positioning, shapes, arrows, decorations.pathreplacing}
\usetikzlibrary{shapes.geometric, arrows, calc, intersections}

\begin{document}
    \tikzstyle{decision} = [diamond, draw, fill=blue!20, 
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
    \tikzstyle{block} = [rectangle, draw, fill=green!10, 
    text width=25em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block2} = [rectangle, draw, fill=lime!35, 
    text width=12em, text centered, rounded corners, minimum height=3em]
    \tikzstyle{block3} = [rectangle, draw, fill=black!10!green, 
    text width=12em, text centered, rounded corners, minimum height=3em]
    \tikzstyle{block4} = [rectangle, draw, fill=black!10!green, 
    text width=8em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block5} = [rectangle, draw, fill=black!10!green, 
    text width=5em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block6} = [rectangle, draw, fill=black!10!green, 
    text width=5em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block7} = [rectangle, draw, fill=black!10!green, 
    text width=13em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block8} = [rectangle, draw, fill=black!10!green, 
    text width=6em, text centered, ellipse, minimum height=4em]
    \tikzstyle{block9} = [rectangle, draw, fill=teal!60, 
    text width=15em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block10} = [rectangle, draw, fill=cyan!60, 
    text width=10em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block11} = [rectangle, draw, fill=white!60, 
    text width=10em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{block12} = [rectangle, draw, fill=cyan!60, 
    text width=15em, text centered, rounded corners, minimum height=3em]
    \tikzstyle{block13} = [rectangle, draw, fill=cyan!30, 
    text width=20em, text centered, rounded corners, minimum height=3em]
    \tikzstyle{line} = [draw, -latex']
    \tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=2cm,
    minimum height=4em]
    \vspace{1cm}

    \begin{figure}[!h]
        \centering
        \begin{tikzpicture}[node distance = 2cm, auto]
        % Place nodes
        \node [block] (title) {\textbf{JORDAN-CHEVALLEY DECOMPOSITION FOR\\ EEG SIGNALS DURING EPILEPTIC SEIZURES}};
        \node [block2, below of=title, node distance=2.3cm] (chap1) {\textbf{Chapter 1}\\ Introduction};
        \node [block3, below of=chap1, node distance=2.3cm] (chap2) {\textbf{Chapter 2}\\ Epileptic seizure};
        \node [block4, below of=chap2, node distance=2.3cm] (patient) {Patient and EEG signals recording};
        \node [block5, left of=patient, node distance=4cm] (fttm) {FTTM};
        \node [block6, right of=patient, node distance=4cm](flateeg) {Flat EEG};
        \node [block7, below of=patient, node distance=2.5cm](KR) {Krohn-Rhodes decomposition of EEG signals};
        \node [block8, below of=KR, node distance=2.5cm](JC) {Jordan-Chevalley decomposition};
        \node[block8, left of=JC, node distance=5cm](matrix) {Matrix partial order};
        \node[block8, right of=JC, node distance=5cm](prime) {Additive of prime number theory};
        \node[block9, below of=JC, node distance=2.8cm](chap3) {\textbf{Chapter 3}\\ Ordering of matrices by precede operator};
        \node [block9, below of=fttm, node distance =10cm](partial) {\textbf{Chapter 4}\\ Jordan-Chevalley decomposition of elementary EEG signals};
        \node [block9, below of=flateeg, node distance=10cm](chap5) {\textbf{Chapter 5}\\ Pseudo-Goldbach Theorem};
        \node[block12, below of=chap3, node distance=4.5cm](chap6) {\textbf{Chapter 6}\\ Implementation};
        \node[block13, below of=chap6, node distance=2.3cm](chap7) {\textbf{Chapter 7}\\ Conclusion and Recommendation};

        \node[left of=JC, xshift=6cm, yshift=1cm](m) {};
        \node[right of=JC, xshift=-6cm, yshift=1cm](p) {};
        \draw [thick,dash dot] (m) -- (p);

        \node[left of=JC, xshift=5.2cm, yshift=1.2cm](m) {Introduction};  

        Draw edges
        \path [line] (title) -- (chap1);
        \path [line] (chap1) -- (chap2);
        \path [line] (chap2) -- (patient);
        \path [line] (patient) -- (fttm);
        \path [line] (patient) -- (flateeg);
        \path [line] (fttm) |-  (KR);
        \path [line] (flateeg) |-  (KR);
        \path [line] (KR) -- (JC);
        \path [line] (JC) -- (matrix);
        \path [line] (JC) -- (prime);
        \path [line] (JC) -- (chap3);
        \path [line] (chap3) -| (partial);
        \path [line] (chap3) -| (chap5);
        \path [line] (partial) -- (chap5);
        \path [line] (chap3) -- (chap6);
        \path [line] (chap6) -- (chap7);
        \end{tikzpicture}
        \caption{Research framework}
        \label{fig:overview}
    \end{figure}
\end{document}

相关内容