我的问题非常类似这问题。但是,我无法在我的图中使用此解决方案。
我想用一个有两个角的箭头连接两个节点。这是我的代码:
\documentclass[12pt]{article}
\usepackage{setspace,amsmath,graphicx,float}
\usepackage[english]{babel}
\usepackage[natbibapa]{apacite}
\usepackage{times}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,arrows.meta,positioning,calc}
\begin{document}
\begin{figure}[H]
\centering
\tikzstyle{block} = [draw, rectangle, minimum height=5.5em, minimum width=19em]
\tikzstyle{smallblock} = [draw, rectangle, minimum height=5.5em, minimum width=9em]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]
\begin{tikzpicture}[auto,node distance=7cm,>=latex',align=center]
\node [input, name=input] {};
\node [block, rounded corners=5pt, right of=input] (A) {Start with the narrowest product\\ or geographic market definition.};
\node [block, rounded corners=5pt, below of=A, node distance=3.5cm] (B) {Is it profitable for a monopoly producer of\\ that product to increase prices in a small but\\ significant and nontransitory way?};
\node [block, rounded corners=5pt, below of=B, node distance=3.5cm] (C) {There must be at least one good substitute\\ excluded from the current market definition.\\ Expand the market to include it.};
\node [block, rounded corners=5pt, below of=C, node distance=3.5cm] (D) {Now have a multiproduct monopolist.\\ Could he profitably raise prices?};
\node [smallblock, rounded corners=5pt, right of=D, node distance=8cm] (E) {Stop.\\ Market definition\\ is wide enough.};
\draw [-{Latex[length=3mm]}] (A) -- node[auto][name=1] [right]{} (B);
\draw [-{Latex[length=3mm]}] (B) -- node[auto][name=2] [right]{No} (C);
\draw [-{Latex[length=3mm]}] (C) -- node[auto][name=3] [right]{} (D);
\draw [-{Latex[length=3mm]}] (D) -- node[auto][name=4] [above]{Yes} (E);
\draw [-{Latex[length=3mm]}] (B) -| node[near start][name=5] [above]{Yes} (E);
\draw [-{Latex[length=3mm]}] (D) -- +(0,1)|- node[auto][name=6] [left]{No} (C);
\end{tikzpicture}
\caption[Illustration of an HMT decision tree]{Illustration of an HMT decision tree \citep{QuantTech}.}\label{AlgorithmHMT}
\end{figure}
\end{document}
我想将 D 块与 C 块连接起来(参见最后一个\draw
),但代码-- +(0,1)|- node
(如另一个问题中所述)不起作用。我当然尝试过修改它,但并没有取得什么进展。
有人可以帮忙吗?
答案1
像这样?
(我猜你喜欢上面这种东西)
我大幅重写了你的 MWE
- 弃用
\tikzstyle{<name>} = [...]
我用tikzpicture
as选项替换的选项<name>/.style = {....}
(请参阅下面的 MWE) - 正确
tikzlibrary{positioning}
的语法例如left=of <node name>
- 对于节点距离,我
positioning
再次考虑并定义node distance = <vertical> and <horizontal>
。对于距离,我选择的长度比你小得多(否则图片超出页面) - 对于相对定位,
+
您需要明确定义节点的锚点:(D.west) -- + (-1,0)
。
完成 MWE:
\documentclass[12pt]{article}
\usepackage{setspace,amsmath,graphicx,float}
\usepackage[english]{babel}
\usepackage[natbibapa]{apacite}
\usepackage{times}
\usepackage{tikz}
\usetikzlibrary{arrows, arrows.meta, calc, positioning, quotes, shapes}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[
auto,
node distance = 11mm and 22mm,
base/.style = {draw, rounded corners=5pt, minimum height=5.5em,
align=center},
block/.style = {base, minimum width=19em},
smallblock/.style = {base, minimum width=9em},
]
\coordinate (in);
\node [block,right=of in] (A) {Start with the narrowest product\\
or geographic market definition.};
\node [block,below=of A ] (B) {Is it profitable for a monopoly producer of\\
that product to increase prices in a small but\\
significant and nontransitory way?};
\node [block,below=of B ] (C) {There must be at least one good substitute\\
excluded from the current market definition.\\
Expand the market to include it.};
\node [block,below=of C ] (D) {Now have a multiproduct monopolist.\\
Could he profitably raise prices?};
\node [smallblock,right=of D] (E) {Stop.\\
Market definition\\
is wide enough.};
\draw [-{Latex[length=3mm]}]
(A) edge (B)
(B) edge ["No"] (C)
(C) edge (D)
(D) edge ["Yes"] (E);
\draw [-{Latex[length=3mm]}]
(B) -| node[pos=0.25,name=5] {Yes} (E);
\draw [-{Latex[length=3mm]}]
(D.west) -- +(-1,0) |- node[pos=0.25] {No} (C);
\end{tikzpicture}
\caption[Illustration of an HMT decision tree]
{Illustration of an HMT decision tree \citep{QuantTech}.}
\label{AlgorithmHMT}
\end{figure}
\end{document}