无法在流程图中的文本框中添加多行

无法在流程图中的文本框中添加多行
% flowchart drawing
\documentclass[a4paper, 12pt]{report}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}



\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\tikzstyle{rect} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=white]
\tikzstyle{arrow} = [thick,->,>=stealth]
\usetikzlibrary{shapes.multipart}

\begin{document}
\begin{figure}[H]
    \centering
    \begin{tikzpicture}[node distance=2cm]
        \node (one) [rect] {Input excitation $p_{i+1}$ };
        \node (two) [rect, below of=one] {Calculate displacement response: $x_{i+1} = x_{i} + \Delta t \mathit{x1}_{i} +  \frac{\Delta t^2}{2} \mathit{x2}_{i}$ };
        \node(three)[rect, below of=two]{Impose $x_{i+1}$ on test structure};
        \node(four)[rect, below of=three]{Measure restoring forces from $\mathit{fs}_{i+1}$ from the test  structure}; 
        \node(five)[rect, below of=four]{Calculate: $\mathit{x2}_{i+1} = \left[m + \frac{\mathit{\Delta t}}{2} c\right]^{-1} \left[p_{i+1} - \mathit{fs}_{i+1} - c \mathit{x1}_{i} - \frac{\mathit{\Delta t}}{2} c \mathit{x2}_{i}\right]  \mathit{x1}_{i+1} = \mathit{x1}_{i} + \frac{\mathit{\Delta t}}{2}\left(\mathit{x2}_{i} + \mathit{x2}_{i+1}\right) $};
        \node(six)[rect, below of=five]{set $i = i+1$};
        \draw [arrow] (one) -- (two);
        \draw [arrow] (two) -- (three);
        \draw [arrow] (three) -- (four);
        \draw [arrow] (four) -- (five);
        \draw [arrow] (five) -- (six);
        \draw [arrow] (six.east) -- ++(5, 0) --  ++ (0, 10) -- (one) ;
    \end{tikzpicture}
    \caption{Newmark Explicit Scheme flowchart}
    \label{flowchart}
\end{figure}


\end{document}

答案1

像这样?

在此处输入图片描述

对于上面的流程图,我在您的 MWE(最小工作示例)中做了以下更改:

  • 定义text width节点样式rect。我选择其大小为 66 毫米。对于比文本宽度更宽的节点内容,它将被分成更多行(这样就解决了您的主要问题)
  • 由于\tikzstyle语法, instead it I use\tikzset`已过时
  • 对于放置我使用 TikZ 库positioningchains
  • 对于节点之间的箭头使用宏join=by ...
% flowchart drawing
\documentclass[a4paper, 12pt]{report}
\usepackage{caption}

\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains, 
                positioning,
                shapes.geometric,
                shapes.multipart 
                }
\tikzset{rect/.style = {rectangle, draw, rounded corners, 
\tikzset{rect/.style = {rectangle, draw, rounded corners, 
                        minimum width=#1, minimum height=9mm,
                        text width =\pgfkeysvalueof{/pgf/minimum width}-
                                    2*\pgfkeysvalueof{/pgf/inner xsep},
                        align=center,
                        on chain=A, join=by arrow},
       rect/.default = 66mm,
        arrow/.style = {thick,-Stealth}
        }

\begin{document}
\begin{figure}[htb]
    \centering
    \begin{tikzpicture}[
    node distance=7mm and 1mm,
      start chain= A going below
                        ]
\node [rect] {Input excitation $p_{i+1}$ };
\node [rect] {Calculate displacement response:\\[1ex] 
              $x_{i+1} = x_{i} + \Delta t \mathit{x1}_{i} + \frac{\Delta t^2}{2} \mathit{x2}_{i}$ };
\node [rect] {Impose $x_{i+1}$ on test structure};
\node [rect] {Measure restoring forces from $\mathit{fs}_{i+1}$ 
              from the test  structure};
\node [rect] {Calculate:\\ 
              $
              \mathit{x2}_{i+1} =
              \Bigl[m + \frac{\mathit{\Delta t}}{2} c\Bigr]^{-1}
              \Bigl[p_{i+1} - \mathit{fs}_{i+1} - c \mathit{x1}_{i} - %\\
               \frac{\mathit{\Delta t}}{2} c \mathit{x2}_{i}\Bigr]  \mathit{x1}_{i+1}%\\
              = \mathit{x1}_{i} + \frac{\mathit{\Delta t}}{2}\Bigl(\mathit{x2}_{i} + \mathit{x2}_{i+1}\Bigr)
              $
              };
\node [rect] {set $i = i+1$};
        \draw [arrow] (A-6.east) -- ++(1, 0) |- (A-1) ;
    \end{tikzpicture}
    \caption{Newmark Explicit Scheme flowchart}
    \label{flowchart}
\end{figure}
\end{document}

相关内容