![帮助向 TikZ 添加箭头和方框](https://linux22.com/image/446011/%E5%B8%AE%E5%8A%A9%E5%90%91%20TikZ%20%E6%B7%BB%E5%8A%A0%E7%AE%AD%E5%A4%B4%E5%92%8C%E6%96%B9%E6%A1%86.png)
我有一个 TikZ 图,我想修改它。我是 TikZ 新手,如果有人能帮忙,我将不胜感激。我的图是一个带有箭头和数字的流程图:
\tikzstyle{int}=[draw, fill=blue!20, minimum size=2em]
\tikzstyle{init} = [pin edge={to-,black}]
\begin{tikzpicture}[node distance=4.5cm,auto,>=latex']
\node [int, pin={[init]below:Input2}] (a) {Box1};
\node (b) [left of=a,node distance=4.5cm, coordinate] {a};
\node [int] (c) [right of=a] {Box2};
\node [coordinate] (end) [right of=c, node distance=3.5cm]{};
\path[->] (b) edge node {Arrow1} (a);
\path[->] (a) edge node {Arrow2} (c);
\draw[->] (c) edge node {Arrow3} (end) ;
\end{tikzpicture}
答案1
试试这个代码:
\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\tikzstyle{int}=[draw, fill=blue!20, minimum size=2em]
\tikzstyle{init} = [pin edge={to-,black}]
\begin{document}
\begin{tikzpicture}[node distance=4.5cm]
\node [int, pin={[init]below:Input1}] (a) {Box1};
\node (b) [left of=a, coordinate] {a};
\node [int, pin={[init]below:Input2}] (c) [right of=a] {Box2};
\node [coordinate] (end) [right of=c]{};
\path[->] (b) edge node[midway,above] {Arrow1} (a);
\path[->] (a) edge node[midway,above] {Arrow2} (c);
\draw[->] (c) edge node[midway,above] {Arrow3} (end) ;
\end{tikzpicture}
\end{document}
产生以下输出:
编辑1:
新代码:
\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\tikzstyle{int}=[draw, fill=blue!20, minimum size=2em]
\tikzstyle{init} = [pin edge={to-,black}]
\begin{document}
\begin{tikzpicture}[node distance=3.5cm]
\node [int, pin={[init]}] (a) {Input1};
\node (b) [left of=a, coordinate] {a};
\node [int, pin={[init]}] (c) [right of=a] {Input2};
\node [coordinate] (end) [right of=c]{};
\path[->] (b) edge node[midway,above] {Arrow1} (a);
\path[->] (a) edge node[midway,above] {Arrow2} (c);
\draw[->] (c) edge node[midway,above] {Arrow3} (end) ;
\end{tikzpicture}
\end{document}
新输出:
编辑2:
如果您不想在输入框上方出现箭头,请尝试以下代码:
\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\tikzstyle{int}=[draw, fill=blue!20, minimum size=2em]
\tikzstyle{init} = [pin edge={to-,black}]
\begin{document}
\begin{tikzpicture}[node distance=3.5cm]
% \node [int, pin={[init]}] (a) {Input1};
\node [int] (a) {Input1};
\node (b) [left of=a, coordinate] {a};
% \node [int, pin={[init]}] (c) [right of=a] {Input2};
\node [int] (c) [right of=a] {Input2};
\node [coordinate] (end) [right of=c]{};
\path[->] (b) edge node[midway,above] {Arrow1} (a);
\path[->] (a) edge node[midway,above] {Arrow2} (c);
\draw[->] (c) edge node[midway,above] {Arrow3} (end) ;
\end{tikzpicture}
\end{document}
产生输出: