流程图的 tikz 容器中的标题

流程图的 tikz 容器中的标题

我想使用 tikz 创建流程图。我想要的流程图如下面附图所示。 在此处输入图片描述

我的问题是:

  1. 是否可以向“容器”添加标题?我无法创建标题
  2. 我想增加连接两个集装箱的线的长度。我该怎么做?

另外,我想增加边的箭头。我不确定在绘制边时该怎么做。代码附在此处。

    \documentclass[12pt]{article}
    \usepackage{tikz}
    \usepackage[active,tightpage]{preview}
    \usetikzlibrary{shapes,arrows,calc,fit,backgrounds,shapes.multipart}
    \tikzset{box/.style={draw, rectangle, rounded corners, thick, node 
    distance=7em, 
    text width=6em, text centered, minimum height=3.5em}}
    \tikzset{line/.style={draw, thick, -latex'}}
    \tikzset{every node/.style={font=\scriptsize}}

    \PreviewEnvironment{tikzpicture}
    %=======================================
    % Adjust the boarder of the flowchart
    %=======================================
    \setlength\PreviewBorder{4pt}%

    \begin{document}
    %************************************************************
    %************************************************************
    %  Define block styles
    %************************************************************
    %************************************************************
    \tikzstyle{block} = [rectangle split, draw, rectangle split parts=2,
text width=14em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{grnblock} = [rectangle, draw, fill=green!20, text width=10em, text centered, rounded corners, minimum height=4em] 
    \tikzstyle{whtblock} = [rectangle, draw, fill=white!20, text width=10em, text centered, minimum height=4em]    
    \tikzstyle{line} = [draw, -latex']
    \tikzstyle{cloud} = [draw, ellipse,fill=white!20, node distance=3cm,    minimum height=4em]  
    \tikzstyle{container} = [draw, rectangle,dashed,inner sep=0.28cm, rounded corners,fill=yellow!20,minimum height=4cm]
    %************************************************************
    %************************************************************ 
    \begin{tikzpicture}[node distance = 2.75cm, auto]
    %************************************************************
    %************************************************************
    %  Draw nodes
    %************************************************************
    %************************************************************

    % ****************************************************
    % ****************************************************
    %===============================================    
    %  Microscale: FEM
    %===============================================  
        \node [whtblock,font=\fontsize{10}{0}\selectfont] (MicFEM) {Finite element mesh \\[0.5em]for microstructure};   
    %===============================================    
    %  Microscale: ROM
    %===============================================     
        \node [whtblock, below of=MicFEM, node distance=2.5cm,font=\fontsize{10}{0}\selectfont] (ROM) {Generate Reduced Order \\[0.5em]Model (ROM)\\[0.3em] parts and order};

    %===============================================    
    %  Micro-morphology
    %===============================================      
       \node [grnblock, left of=MicFEM,,node distance=7cm,font=\fontsize{10}{0}\selectfont] (Morph) {\textbf{Microstructure:}\\[0.75em]Morphological properties,\\ e.g. fiber volume fraction, cell type};    
    %===============================================    
    %  Constituent elastic parameters
    %===============================================  
       \node [block, right of=MicFEM,node distance=7cm,rectangle split part fill={orange!20,blue!5},font=\fontsize{10}{0}\selectfont] (ConstElasProp) {\textbf{Constituent Elastic Parameters}
\nodepart[text width=3cm]{two} $E^{(f)}_{1},E^{(f)}_{3},G^{(f)}_{13},\nu^{(f)}_{12},\nu^{(f)}_{31}$\\[0.3em]$E^{(m)},\nu^{(m)}$};
    %===============================================    
    %  CoefTens Compute
    %===============================================      
      \node [whtblock, below of=ROM, node distance=2.5cm,font=\fontsize{9}{0}\selectfont] (CfTns) {Compute \\[0.5em]coefficient tensors\\[0.5em] (\textbf{CoefTensCompute})\\[0.4em] \textcolor{blue}{In-house code}};

    % ****************************************************
    % ****************************************************
    %===============================================    
    %  Macroscale: FEM
    %===============================================    
      \node [cloud, below of=CfTns, node distance=3.5cm,font=\fontsize{10}{0}\selectfont] (MacFEM) {Macroscale FE input file};

    %===============================================    
    %  Macroscale: Geometry, BCs and other details
    %===============================================     
      \node [grnblock, left of=MacFEM, node distance=7cm,font=\fontsize{10}{0}\selectfont] (MacInpFile) {\textbf{Structure:}\\[0.5em] Component layup \\geometry, \\boundary conditions,\\ discretization}; 
    %===============================================    
    %  ABAQUS
    %===============================================      
      \node [whtblock, below of=MacFEM,font=\fontsize{10}{0}\selectfont] (ABAQ) {FE analysis\\[0.2em]\textcolor{blue}{Commercial code}};   
    %===============================================    
    %  UMAT code
    %===============================================      
      \node [whtblock, right of=ABAQ, node distance=7cm,font=\fontsize{10}{0}\selectfont] (UMAT) {User-defined \\[0.3em]material subroutine\\[0.3em] (\textbf{UMAT})\\[0.3em] \textcolor{blue}{In-house code}}; 
   %===============================================    
   %  Constituent damage parameters
   %===============================================  
     \node [block, right of=MacFEM,node distance=7cm,rectangle split part fill={orange!20,blue!5},font=\fontsize{10}{0}\selectfont] (MatParm) {\textbf{Constituent Damage Parameters}
      \nodepart[text width=3cm]{two}$\epsilon^{(f)}_{0},\alpha^{(f)},\beta^{(f)},c^{(f)},\epsilon^{(f)}_\textrm{\scriptsize f}$\\$\epsilon^{(m)}_{0},\alpha^{\textrm{\scriptsize{N}}(m)},\alpha^{\textrm{\scriptsize{S}}(m)},\beta^{\textrm{\scriptsize{N}}(m)}$\\$\beta^{\textrm{\scriptsize{S}}(m)},c^{(m)}, \epsilon^{\textrm{\scriptsize{N}}(m)}_\textrm{\scriptsize f},\epsilon^{\textrm{\scriptsize{S}}(m)}_\textrm{\scriptsize f},\eta$};    
   % ****************************************************
   % ****************************************************    
   %===============================================    
   %  Output
   %===============================================
      \node [block, below of=ABAQ, node distance=3cm,rectangle split part fill={blue!20,white},font=\fontsize{10}{0}\selectfont] (Output) {\textbf{Output}
\nodepart[text width=3cm]{two}Ultimate strength,\\[0.3em]damage contours };
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   %   CONTAINERS
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \begin{scope}[on background layer]
        \node [container,fit=(MicFEM)(ROM)(CfTns)] (MICRO) {};
        \node at (MICRO.north) [above right,node distance=0 and 0,font=\fontsize{12}{0}\selectfont] {\textbf{Microscale Analysis}};
    %-----------------------------------------------------------
        \node[container, fit=(ABAQ) (MacFEM)] (MACRO) {};
        \node at (MACRO.north) [above right,node distance=0 and 0,font=\fontsize{12}{0}\selectfont] {\textbf{Macroscale Analysis}};
    \end{scope}
    %************************************************************
    %************************************************************
    %  Draw edges
    %************************************************************
    %************************************************************
      \path [line] (MicFEM) -- (ROM);
      \path [line] (ROM) -- (CfTns);
      \path [line] (MacFEM) -- (ABAQ);
      \path [line] (MatParm) -- (UMAT);
      \path [line] (MacInpFile) -- (MacFEM);
      \path [line] (MICRO) -- (MACRO);
      \path [line] (Morph) -- (MicFEM);
      \path [line] (ConstElasProp) -- (MicFEM);
      \path [line] (UMAT) -- (ABAQ);
      \path [line] (MACRO) -- (Output);
      \end{tikzpicture}
    \end{document}

我想要容器的标题类似于下面的图片 在此处输入图片描述

答案1

我认为三个问题中有两个可以直接回答。

  1. “微观尺度分析”和“宏观尺度分析”标题的位移来自于键above right,我用更合适的锚点替换了它们。
  2. arrows库已被 取代arrows.meta。例如,如果您将其替换latex'{Latex[length=2mm,width=1mm]},则可以将箭头放大。(您定义了line两次样式。)
  3. 尽管我没有恰恰明白您所说的“我想增加连接两个容器的线的长度。我该怎么做?”的意思,我刚刚意识到您没有使用库positioning,这使得节点的相对定位变得更容易、更优雅。我改变了这一点。特别是,您现在可以通过说例如来精确控制节点之间的距离below=3cm of ...。请注意语法上细微但重要的区别:below of=...您需要写below=of ...below=<distance> of ...,而不是distance节点边界之间的距离。
  4. 我还将UMAT节点移动到 的高度ABAQ和 之下MatParm.center。这可以通过使用(ABAQ.center -| MatParm.center)来执行,请参阅这个答案了解详情。

结果:

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\usetikzlibrary{shapes,arrows.meta,calc,fit,backgrounds,shapes.multipart,positioning}
\tikzset{box/.style={draw, rectangle, rounded corners, thick, node 
distance=7em, 
text width=6em, text centered, minimum height=3.5em}}
%\tikzset{line/.style={draw, thick, -{Latex[length=2mm,width=1mm]}}}
\tikzset{every node/.style={font=\scriptsize}}

\PreviewEnvironment{tikzpicture}
%=======================================
% Adjust the boarder of the flowchart
%=======================================
\setlength\PreviewBorder{4pt}%

\begin{document}
%************************************************************
%************************************************************
%  Define block styles
%************************************************************
%************************************************************
\tikzset{block/.style={rectangle split, draw, rectangle split parts=2,
text width=14em, text centered, rounded corners, minimum height=4em},
grnblock/.style={rectangle, draw, fill=green!20, text width=10em, text centered, rounded corners, minimum height=4em}, 
whtblock/.style={rectangle, draw, fill=white!20, text width=10em, text centered, minimum height=4em},    
line/.style={draw, -{Latex[length=2mm,width=1mm]}},
cloud/.style={draw, ellipse,fill=white!20, node distance=3cm,    minimum height=4em},  
container/.style={draw, rectangle,dashed,inner sep=0.28cm, rounded
corners,fill=yellow!20,minimum height=4cm}}
%************************************************************
%************************************************************ 
\begin{tikzpicture}[node distance = 1.25cm, auto]
%************************************************************
%************************************************************
%  Draw nodes
%************************************************************
%************************************************************

% ****************************************************
% ****************************************************
%===============================================    
%  Microscale: FEM
%===============================================  
  \node [whtblock,font=\fontsize{10}{0}\selectfont] (MicFEM) {Finite element mesh \\[0.5em]for microstructure};   
%===============================================    
%  Microscale: ROM
%===============================================     
\node [whtblock, below=of MicFEM, node distance=2.5cm,font=\fontsize{10}{0}\selectfont] (ROM) {Generate Reduced Order \\[0.5em]Model (ROM)\\[0.3em] parts and order};

%===============================================    
%  Micro-morphology
%===============================================      
 \node [grnblock, left=of MicFEM,,node distance=7cm,font=\fontsize{10}{0}\selectfont] (Morph) {\textbf{Microstructure:}\\[0.75em]Morphological properties,\\ e.g. fiber volume fraction, cell type};    
%===============================================    
%  Constituent elastic parameters
%===============================================  
 \node [block, right=of MicFEM,node distance=7cm,rectangle split part fill={orange!20,blue!5},font=\fontsize{10}{0}\selectfont] (ConstElasProp) {\textbf{Constituent Elastic Parameters}
\nodepart[text width=3cm]{two} $E^{(f)}_{1},E^{(f)}_{3},G^{(f)}_{13},\nu^{(f)}_{12},\nu^{(f)}_{31}$\\[0.3em]$E^{(m)},\nu^{(m)}$};
%===============================================    
%  CoefTens Compute
%===============================================      
\node [whtblock, below=of ROM, node distance=2.5cm,font=\fontsize{9}{0}\selectfont] (CfTns) {Compute \\[0.5em]coefficient tensors\\[0.5em] (\textbf{CoefTensCompute})\\[0.4em] \textcolor{blue}{In-house code}};

% ****************************************************
% ****************************************************
%===============================================    
%  Macroscale: FEM
%===============================================    
\node [cloud, below=of CfTns, node distance=3.5cm,font=\fontsize{10}{0}\selectfont] (MacFEM) {Macroscale FE input file};

%===============================================    
%  Macroscale: Geometry, BCs and other details
%===============================================     
\node [grnblock, left=of MacFEM, node distance=7cm,font=\fontsize{10}{0}\selectfont] (MacInpFile) {\textbf{Structure:}\\[0.5em] Component layup \\geometry, \\boundary conditions,\\ discretization}; 
%===============================================    
%  ABAQUS
%===============================================      
\node [whtblock, below=of MacFEM,font=\fontsize{10}{0}\selectfont] (ABAQ) {FE analysis\\[0.2em]\textcolor{blue}{Commercial code}};   
%===============================================    
%  Constituent damage parameters
%===============================================  
\node [block, right=of MacFEM,node distance=7cm,rectangle split part fill={orange!20,blue!5},font=\fontsize{10}{0}\selectfont] (MatParm) {\textbf{Constituent Damage Parameters}
\nodepart[text width=3cm]{two}$\epsilon^{(f)}_{0},\alpha^{(f)},\beta^{(f)},c^{(f)},\epsilon^{(f)}_\textrm{\scriptsize f}$\\$\epsilon^{(m)}_{0},\alpha^{\textrm{\scriptsize{N}}(m)},\alpha^{\textrm{\scriptsize{S}}(m)},\beta^{\textrm{\scriptsize{N}}(m)}$\\$\beta^{\textrm{\scriptsize{S}}(m)},c^{(m)}, \epsilon^{\textrm{\scriptsize{N}}(m)}_\textrm{\scriptsize f},\epsilon^{\textrm{\scriptsize{S}}(m)}_\textrm{\scriptsize f},\eta$};    
%===============================================    
%  UMAT code
%===============================================      
\node [whtblock, font=\fontsize{10}{0}\selectfont] (UMAT) at 
(ABAQ.center -| MatParm.center) {User-defined \\[0.3em]material subroutine\\[0.3em] (\textbf{UMAT})\\[0.3em] \textcolor{blue}{In-house code}}; 
% ****************************************************
% ****************************************************    
%===============================================    
%  Output
%===============================================
\node [block, below=of ABAQ, node distance=3cm,rectangle split part fill={blue!20,white},font=\fontsize{10}{0}\selectfont] (Output) {\textbf{Output}
\nodepart[text width=3cm]{two}Ultimate strength,\\[0.3em]damage contours };
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   CONTAINERS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{scope}[on background layer]
  \coordinate (aux1) at ([yshift=3mm]MicFEM.north);
  \node [container,fit=(aux1) (ROM)(CfTns)] (MICRO) {};
  \node at (MICRO.north) [fill=white,draw,font=\fontsize{12}{0}\selectfont] {\textbf{Microscale Analysis}};
%-----------------------------------------------------------
  \coordinate (aux2) at ([yshift=3mm]MacFEM.north);
  \node[container, fit=(aux2) (MacFEM) (ABAQ)] (MACRO) {};
  \node at (MACRO.north) [fill=white,draw,font=\fontsize{12}{0}\selectfont] 
  (MACRO-label) {\textbf{Macroscale Analysis}};
\end{scope}
%************************************************************
%************************************************************
%  Draw edges
%************************************************************
%************************************************************
\path [line] (MicFEM) -- (ROM);
\path [line] (ROM) -- (CfTns);
\path [line] (MacFEM) -- (ABAQ);
\path [line] (MatParm) -- (UMAT);
\path [line] (MacInpFile) -- (MacFEM);
\path [line] (MICRO) -- (MACRO-label);
\path [line] (Morph) -- (MicFEM);
\path [line] (ConstElasProp) -- (MicFEM);
\path [line] (UMAT) -- (ABAQ);
\path [line] (MACRO) -- (Output);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

您可以简单地将节点标题添加为节点标签:

\documentclass[tikz,margin=3.141529mm]{standalone}

\begin{document}
    \begin{tikzpicture}[
    box/.style = {draw, semithick, dashed, rounded corners, fill=yellow,
                  text width=44mm, align=center,
                  inner xsep=1mm, inner ysep=3mm, yshift=1mm, outer sep=0mm,
                  %
                  label={[name=#1,draw, fill=white, anchor=center]above:#2}
                  }
                        ]
\node (a1)  [box=title] {Here comes my nodes:\\
                        1. \dots    \\
                        2. \dots
                        };
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容