我正在尝试实现以下目标:
但是我不知道如何制作这些箭头。我有一些代码可以给出几乎正确的东西,但有些地方很乱,无法自动选择我想要的路径(重叠节点等)
\path [draw, -latex'] (START) |- (DUMMY) |- (DUMMY2) |- (GOAL);
我制作了两个虚拟节点,试图让这个东西遵循我想要的路径,也就是向下、向左、向下,就像上图中的“预热炉”->“准备工厂和服务”步骤一样。
有人能帮我指点如何更好地引导这些路径吗?如果可能的话,不要让额外的节点造成混乱?我目前被困在这个问题上,不知道该怎么办。我在谷歌上搜索了很多,但只得到了部分答案(比如上面的那个)。
答案1
下次,请提供一个最小工作示例,以便人们不必从图像中复制每个单词,而至少可以剪切粘贴文档的基本结构和图表的文本内容。
此解决方案使用forest
并自动构建和添加节点开头的标签。为此,我得到了非常快速、准确的帮助Sašo Živanović 的回答致我的关于避免多重标签的问题。
\documentclass[tikz, border=5pt]{standalone}
\usepackage{forest}
\usepackage[T1]{fontenc}
\usepackage{textcomp,fixltx2e}
\usetikzlibrary{arrows.meta,shadows}
\begin{document}
\forestset{
tree node/.style = {inner sep=2pt, rounded corners = 2pt, font=\sffamily, rectangle, draw, thick, fill=white, align=center, drop shadow},
placing node/.style={inner sep=0pt, outer sep=0pt, draw=none, skipping path},
skipping path/.style={
edge path={
\noexpand\path [\forestoption{edge}, thick]
(!u.parent anchor) -- (.south)\forestoption{edge label};
},
},
/tikz/plan label/.style={font=\sffamily\scriptsize},
}
\begin{forest}
for tree={
parent anchor=south,
child anchor=north,
l sep+=5pt,
edge path={
\noexpand\path [-{Stealth[]}, \forestoption{edge}, thick]
(!u.parent anchor) -- +(0,-5pt) -| (.child anchor)\forestoption{edge label};
},
},
set root label/.style={
content/.wrap 2 pgfmath args={##1. ##2}{n()}{content()},
tree node
},
set node label/.style={
content/.wrap 3 pgfmath args={##1.##2 ##3}{n("!r")}{n()}{content()},
tree node
},
set node super label/.style={
content/.wrap 4 pgfmath args={##1.##2.##3 ##4}{n("!r")}{n("!uu")}{n()}{content()},
tree node
},
before typesetting nodes={% where contains implicit for tree loop: https://tex.stackexchange.com/a/218995/: Sašo Živanović
for tree={
if level=0{
set root label,
% content={O. #1},
}{
if level=1{
set node label,
}{
if level=3{
set node super label,
}{
},
},
},
},
}
[Warm\\up furnace
[Prepare\\plant and\\services
[, placing node, label={[plan label]right:Plan 0.1: Do in any order}
[Ensure\\plant is\\ready, calign with current
[,phantom, tier=bottom]
]
[Ensure\\gas-oil is\\available
]
[Ensure O\textsubscript{2}\\analysis system\\is working
]
]
]
[\\Start air\\blower, edge label={node [plan label, anchor=south east, above left, midway] {Plan 0: Do in order};}
]
[\\Start oil\\pump
]
[Head\\oil to\\800\textcelsius
[, placing node, tier=bottom, label={[plan label]left:Plan 0.4: Raise temperature to 800\textcelsius{} while monitoring O\textsubscript{2} and $\triangle$T}
[Increase\\temperature controller\\as per chart
]
[\\Monitor\\O\textsubscript{2}
]
[\\Monitor\\temperature
]
[Switch\\furnace to\\automatic, calign with current
]
]
]
]
;
\end{forest}
\end{document}
答案2
pstricks
具有psmatrix
环境和相对较短的代码的解决方案:
\documentclass[12pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[pdf, x11names]{pstricks}%
\usepackage{pst-node, pst-blur}
\usepackage{siunitx}
\sisetup{detect-family, mode=text}
\usepackage{twoopt}
\newcommandtwoopt\mybox[3][1.6cm][2.5cm]{\psframebox[shadow=true, blur=true, framearc=0.05]{\parbox[t][#1][c]{#2}{\centering#3}}}
\begin{document}
\psset{nodesep=0pt, arrows=->, angleA=-90,angleB=90, armA = 1.5cm, armB=0.5cm, colsep=0.5cm, rowsep=2cm, linearc=0.05}%
\sffamily
\begin{psmatrix}
%%% nodes
& \mybox[1.2cm]{0. Warm up \\ furnace}\psspan{2}\\
\mybox{0.1 Prepare \\ plant and \\ services} & \mybox{0.2 Start \\ air blower} & \mybox{0.3 Start \\ oil pump} & \mybox{0.4 Heat \\ oil to \\ \SI{800}{\celsius}} \\
\mybox{0.1.1 Ensure \\ plant is \\ ready} & \mybox{0.1.2 Ensure \\ gas-oil is \\ avalaible} & \mybox[1.6cm][3.2cm]{0.1.3 Ensure O\textsuperscript2 \\ analysis system \\ is working}\\
\mybox[1.6cm][4cm]{0.4.1 Increase \\ temperature controller \\ as per chart} & \mybox{0.4.2 \\ Monitor \\ O\textsuperscript2} & \mybox{0.4.3 \\ Monitor \\ temperature} & \mybox{0.4.4 Switch \\ furnace to \\ automatic}
%%% arrows
\ncangle{1,2}{2,1}\nbput[npos=1.72]{Plan 0: Do in order}\ncangle{1,2}{2,2}\ncangle{1,2}{2,3}\ncangle{1,2}{2,4}
\ncangle{2,1}{3,1}\ncangle{2,1}{3,2}\ncangle{2,1}{3,3}\naput[npos=1.32]{Plan 0.1: Do in any order}
\psset{armA=5.4cm}
\ncangle{2,4}{4,1}\nbput[npos=0.92 ]{Plan 0.4: Raise temperature to \SI{800}{\celsius} while monitoring O\textsuperscript{2} and $\Delta$T}\ncangle{2,4}{4,2}\ncangle{2,4}{4,3}\ncangle{2,4}{4,4}
\end{psmatrix}
\end{document}