我被困在图表上。以下是我得到的:
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows, fit, positioning, shapes}
\tikzstyle{startstop} = [rectangle, rounded corners, text centered, draw=black]%minimum width=2cm, minimum height=1cm,
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, text centered, draw=black]%minimum width=3cm, minimum height=1cm,
\tikzstyle{decision} = [diamond, text centered, draw=black]%minimum width=3cm, minimum height=1cm,
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{tikzpicture}%[node distance=2cm]
\node (start) [startstop] {Start};
\node (dec1) [decision, below=1 of start] {a=b?};
\node (io1) [io, below left=2 of dec1] {gib gleich aus};
\node (io2) [io, below right=2 of dec1] {gib ungleich aus};
\node (end) [startstop, below left=2 of io2] {Stop};
\draw [arrow] (start) -- (dec1);
\draw [arrow] (dec1.west) node[above] {ja}-|(io1);
\draw [arrow] (io1)|-(end);
\draw [arrow] (dec1.east) node[above] {nein}-|(io2);
\draw [arrow] (io2)|-(end);
\end{tikzpicture}
\end{document}
现在,我怎样才能将文本定位在水平线向下延伸之前的箭头 (ja 和 nein) 上?还有这一行:
\node (io2) [io, below right=2 of dec1] {gib ungleich aus};
让我将一个节点相对于另一个节点定位,但是我可以说,我希望它在下面 1 位、右边 3 位,而不是在两个方向上都 2 位吗?
答案1
如果你使用-|
或|-
路径构造,角落的位置(在你的情况下线变为负的位置)是0.5
。所以你可以这样做
\draw [arrow] (dec1.west) -|(io1) node[pos=0.5,above right]{ja};
\draw [arrow] (dec1.east) -|(io2)node[pos=0.5,above left]{nein};
你可以说
\node (io1) [io, below left=1cm and 2cm of dec1] {gib gleich aus};
其中 中的第一个距离below left=1cm and 2cm
是垂直距离,第二个距离是水平距离。您也可以设置node distance=1cm and 2cm
。
顺便说一句,\tikzstyle
已被弃用。
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes.geometric}
\tikzset{startstop/.style={rectangle, rounded corners, text centered,draw=black},%minimum width=2cm, minimum height=1cm,
io/.style={trapezium, trapezium left angle=70, trapezium right angle=110, text centered, draw=black},%minimum width=3cm, minimum height=1cm,
decision/.style={diamond, text centered, draw=black},%minimum width=3cm, minimum height=1cm,
arrow/.style={thick,->,>=stealth}}
\begin{document}
\begin{tikzpicture}%[node distance=2cm]
\node (start) [startstop] {Start};
\node (dec1) [decision, below=1 of start] {a=b?};
\node (io1) [io, below left=1cm and 2cm of dec1] {gib gleich aus};
\node (io2) [io, below right=1cm and 2cm of dec1] {gib ungleich aus};
\node (end) [startstop, below left=1cm and 2cm of io2] {Stop};
\draw [arrow] (start) -- (dec1);
\draw [arrow] (io1)|-(end);
\draw [arrow] (dec1.west) -|(io1) node[pos=0.5,above right]{ja};
\draw [arrow] (dec1.east) -|(io2)node[pos=0.5,above left]{nein};
\draw [arrow] (io2)|-(end);
\end{tikzpicture}
\end{document}
和
\draw [arrow] (dec1.west) -|(io1) node[pos=0.5,above]{ja};
\draw [arrow] (dec1.east) -|(io2)node[pos=0.5,above]{nein};
以及上述node distance
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes.geometric}
\tikzset{startstop/.style={rectangle, rounded corners, text centered,draw=black},%minimum width=2cm, minimum height=1cm,
io/.style={trapezium, trapezium left angle=70, trapezium right angle=110, text centered, draw=black},%minimum width=3cm, minimum height=1cm,
decision/.style={diamond, text centered, draw=black},%minimum width=3cm, minimum height=1cm,
arrow/.style={thick,->,>=stealth}}
\begin{document}
\begin{tikzpicture}[node distance=1cm and 2cm]
\node (start) [startstop] {Start};
\node (dec1) [decision, below=1 of start] {a=b?};
\node (io1) [io, below left=of dec1] {gib gleich aus};
\node (io2) [io, below right=of dec1] {gib ungleich aus};
\node (end) [startstop, below left=of io2] {Stop};
\draw [arrow] (start) -- (dec1);
\draw [arrow] (io1)|-(end);
\draw [arrow] (dec1.west) -|(io1) node[pos=0.5,above]{ja};
\draw [arrow] (dec1.east) -|(io2)node[pos=0.5,above]{nein};
\draw [arrow] (io2)|-(end);
\end{tikzpicture}
\end{document}
你得到
我也想知道你是否想使用
\node (dec1) [decision, below=1 of start] {$a=b$?};
即方程的数学模式a=b
。