如何在矩阵结构中绘制箭头

如何在矩阵结构中绘制箭头

我想知道如何在这个方案中制作一个特定的箭头。我不知道这是否可行。使用此代码,我需要制作一个从 (rombo1.south) 到 (动量) -- (压力) 的中间箭头的箭头。这可能吗?我不确定,因为它在矩阵结构内。

\documentclass[spanish,a4paper,12pt]{book}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows,snakes,backgrounds}
\usetikzlibrary{shapes.geometric}

\begin{document}    
\thispagestyle{empty}
\begin{center}
\begin{tikzpicture}
\large

\tikzstyle{block} = [rectangle, draw=blue, thick, fill=blue!20, text centered,minimum     height=2em];

\tikzstyle{line} = [draw, thick, -latex',shorten >=0pt];

\tikzstyle{linwit} = [draw, thick, shorten >=0pt];

\tikzstyle{rombo}=[diamond, aspect=2, draw=blue, thick, fill=blue!20, text centered, minimum height=3em];

\matrix [column sep=10mm,row sep=10mm]
{
% row 1
& \node [block,text width=3cm] (t) {$t=t+n\:\Delta t$}; \\
% row 2
&
\node [block,text width=4cm,minimum height=3em] (momentum) {Solve U, V, W\\ equations};
& \node [rombo,text width=2cm] (rombo1) {Converged?};\\
% row 3
& \node [block,text width=4cm] (pressure) {Solve pressure\\ correction}; \\
% row 4
& \node [block,text width=4.5cm] (correct) {Correct velocity,\\ pressure, fluxes}; \
% row 5
& \node [block, text width=3.2cm] (scalars) {Solve k and $\varepsilon$};
& \node [rombo,text width=2cm] (rombo2) {Converged?};\\
% row 6
& \node [block,text width=5cm] (converged) {Solve other scalars};\\
% row 7
& \node [block,text width=4cm] (advance) {Advance to\\ next time step};\\
};


\tikzstyle{every path}=[line]
\path (t) -- (momentum);
\path (momentum) -- (pressure);
\path (pressure) -- (correct);
\path (correct) -- (scalars);
\path (scalars) -- (converged);
\path (converged) -- (advance);
\path (advance.west) -- ++(-2,0) |- (t);
\path (rombo1.west) -- node [above,]{No}(momentum);
\path (rombo1.south) -- ++(0,-1) -- (correct);
\path (rombo2.west) -- node [above,]{No}(scalars);

\end{tikzpicture}

\end{center}

\end{document}

答案1

您可以沿着路径放置一个辅助坐标,然后使用该坐标绘制边缘:

\documentclass[spanish,a4paper,12pt]{book}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows,snakes,backgrounds}
\usetikzlibrary{shapes.geometric}

\begin{document}    
\thispagestyle{empty}
\begin{center}
\begin{tikzpicture}
\large

\tikzset{
block/.style={
  rectangle,
  draw=blue,
  thick, fill=blue!20,
  text centered,
  minimum height=2em
  },
line/.style={
  draw,
  thick,
  -latex',
  shorten >=0pt
  },
linwit/.style={
  draw,
  thick,
  shorten >=0pt
  },
rombo/.style={
  diamond,
  aspect=2,
  draw=blue,
  thick,
  fill=blue!20,
  text centered,
  minimum height=3em
  }
}

\matrix [column sep=10mm,row sep=10mm]
{
% row 1
& \node [block,text width=3cm] (t) {$t=t+n\:\Delta t$}; \\    
% row 2
&
\node [block,text width=4cm,minimum height=3em] (momentum) {Solve U, V, W\\ equations};
& \node [rombo,text width=2cm] (rombo1) {Converged?};\\    
% row 3
& \node [block,text width=4cm] (pressure) {Solve pressure\\ correction}; \\    
% row 4
& \node [block,text width=4.5cm] (correct) {Correct velocity,\\ pressure, fluxes}; \\    
% row 5
& \node [block, text width=3.2cm] (scalars) {Solve k and $\varepsilon$};
& \node [rombo,text width=2cm] (rombo2) {Converged?};\\    
% row 6
& \node [block,text width=5cm] (converged) {Solve other scalars};\\    
% row 7
& \node [block,text width=4cm] (advance) {Advance to\\ next time step};\\
};


\tikzset{every path/.style=line}
\path (t) -- (momentum);
\path (momentum) -- coordinate[pos=0.5] (aux) (pressure);
\path (pressure) -- (correct);
\path (correct) -- (scalars);
\path (scalars) -- (converged);
\path (converged) -- (advance);
\path (advance.west) -- ++(-2,0) |- (t);
\path (rombo1.west) -- node [above]{No}(momentum);
\path (rombo1.south) -- ++(0,-1) -- (correct);
\path (rombo2.west) -- node [above,]{No}(scalars);
\path (rombo1.south) |- (aux);
\end{tikzpicture}

\end{center}

\end{document}

在此处输入图片描述

顺便说一句,\tikzstyle这是旧语法;您应该使用\tikzset它(如我的回答一样)。

\matrix您也可以使用以下库,在不使用的情况下绘制此图positioning

\documentclass[spanish,a4paper,12pt]{book}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows,snakes,backgrounds}
\usetikzlibrary{shapes.geometric,positioning}

\begin{document}    
\thispagestyle{empty}
\begin{center}
\begin{tikzpicture}
\large

\tikzset{
block/.style={
  rectangle,
  draw=blue,
  thick, fill=blue!20,
  text centered,
  minimum height=2em
  },
line/.style={
  draw,
  thick,
  -latex',
  shorten >=0pt
  },
linwit/.style={
  draw,
  thick,
  shorten >=0pt
  },
rombo/.style={
  diamond,
  aspect=2,
  draw=blue,
  thick,
  fill=blue!20,
  text centered,
  minimum height=3em
  }
}

\node [block,text width=3cm] (t) {$t=t+n\:\Delta t$};
\node [block,text width=4cm,minimum height=3em,below=of t] 
  (momentum) {Solve U, V, W  \\ equations};
\node [rombo,text width=2cm,right=of momentum] (rombo1) {Converged?};
\node [block,text width=4cm,below=of momentum] 
  (pressure) {Solve pressure\\ correction};
\node [block,text width=4.5cm,below=of pressure] 
  (correct) {Correct velocity,\\ pressure, fluxes};
\node [block, text width=3.2cm,below=of correct] 
  (scalars) {Solve k and $\varepsilon$};
\node [rombo,text width=2cm,right=of scalars] 
  (rombo2) {Converged?};
\node [block,text width=5cm,below=of scalars] 
  (converged) {Solve other scalars};
\node [block,text width=4cm,below=of converged] 
  (advance) {Advance to\\ next time step};

\tikzset{every path/.style=line}
\path (t) -- (momentum);
\path (momentum) -- coordinate[pos=0.5] (aux) (pressure);
\path (pressure) -- (correct);
\path (correct) -- (scalars);
\path (scalars) -- (converged);
\path (converged) -- (advance);
\path (advance.west) -- ++(-2,0) |- (t);
\path (rombo1.west) -- node [above]{No}(momentum);
\path (rombo1.south) -- ++(0,-1) -- (correct);
\path (rombo2.west) -- node [above,]{No}(scalars);
\path (rombo1.south) |- (aux);
\end{tikzpicture}

\end{center}

\end{document}

在此处输入图片描述

相关内容