如何才能实现以下所需输出,理想情况下无需声明其他坐标/节点?我希望铸造节点通过垂直线连接到碱性氧气转炉和电弧炉之间的水平线。此外,如何才能使整个铸造节点组相对于碱性氧气转炉和电弧炉节点居中?
姆韦
\documentclass[margin=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\begin{document}
\tikzset{%
every node/.style={rectangle,draw,inner ysep=3mm,text centered}
}
\begin{tikzpicture}[node distance=20mm and 10mm]
\node (boc) {Basic Oxygen Converter};
\node[right=of boc] (eaf) {Electric Arc Furnace};
\draw (boc) -- (eaf);
\node[below left=15mm and 10mm of $(boc) !.5! (eaf)$] (mediumslabcasting) {Medium Slab Casting};
\node[left=of mediumslabcasting] (thickslabcasting) {Thick Slab Casting};
\node[right=of mediumslabcasting] (bloomcasting) {Bloom Casting};
\node[right=of bloomcasting] (billetcasting) {Billet Casting};
\draw (mediumslabcasting) |- ($(boc) !.5! (eaf)$);
\draw (thickslabcasting) |- ($(boc) !.5! (eaf)$);
\draw (bloomcasting) |- ($(boc) !.5! (eaf)$);
\draw (billetcasting) |- ($(boc) !.5! (eaf)$);
\end{tikzpicture}
\end{document}
答案1
您可以将节点包含到两个不同的matrix
节点中,这两个节点可以轻松地相互叠放。之后,您只需绘制链接即可。我使用了两个辅助坐标。
\documentclass[margin=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, matrix, calc}
\begin{document}
\tikzset{%
mynode/.style= {anchor=center, rectangle, draw, inner ysep=3mm, text centered}
}
\begin{tikzpicture}[node distance=20mm and 10mm]
\matrix (top) [matrix of nodes, nodes=mynode, column sep=10mm]{
Basic Oxygen Converter &
Electric Arc Furnace\\};
\matrix (bottom) [matrix of nodes, nodes=mynode, below=1cm of top, column sep=5mm] {
Medium Slab Casting & Thick Slab Casting & Bloom Casting & Billet Casting\\
};
\draw (top-1-1.east) -- coordinate (aux1) (top-1-2.west);
\path (aux1) -- coordinate (aux2) (aux1|-bottom-1-1.north);
\draw (aux1)--(aux2);
\foreach \i [count=\ni] in {1,2,3,4}
\draw (bottom-1-\ni.north)|-(aux2);
\end{tikzpicture}
\end{document}
答案2
伊格纳西已经解释了如何使用\matrix
,我建议使用更自动化的方式,使用宏将一堆节点并排放置
\tikzCenterNodes[<options>]{list of <opt>/<text>}
<options>
它使用(这应该用于命名矩阵和放置它)和列表的节点构造一个 1 行矩阵,其中在和节点的文本<opt>
之间使用。\node
<text>
我没有添加任何安全保护措施,以防仅使用一个节点,\tikzCenterNodes
但在这种情况下您可以使用普通\node
宏。
由于您使用了every node
样式(也适用于\matrix
),我使用该every outer matrix
样式来删除或重置矩阵的一些默认值,因为我们希望它紧密贴合我们的节点行。
我在用着我的图书馆
ext.positioning-plus
对于 PGFMath 函数
x_node_dist
,y_node_dist
这样我们就不必在一个或多个地方给出节点距离(水平节点距离成为值column sep
),并且ext.paths.ortho
这使我们能够使用正交连接形式为
|-|
(vertical horizontal vertical
),我再次使用,y_node_dist
以便|-|
连接的水平部分位于节点之间的中间。
它有一个辅助坐标mid
,位于顶部两个节点边界的中间。
代码
\documentclass[tikz,margin=1cm]{standalone}
\usetikzlibrary{ext.positioning-plus,ext.paths.ortho}
\newcommand*\tikzCenterNodes[2][1]{% only
\matrix[
every outer matrix/.append style={/pgf/inner sep=+0pt, /pgf/outer sep=+0pt, draw=none, fill=none},
/utils/place 1st node/.code args={##1/##2,##3}{\node##1{##2};},
/utils/place oth node/.code args={##1/##2}{\pgfmatrixnextcell\node##1{##2};},
/utils/place other nodes/.style args={##1,##2}{/utils/place oth node/.list={##2}},
column sep=x_node_dist,
#1] {
\tikzset{/utils/place 1st node={#2},/utils/place other nodes={#2}}
\\};
}
\begin{document}
\begin{tikzpicture}[
node distance=20mm and 10mm,
nodes={rectangle, draw, inner ysep=3mm, text depth=+0pt}
]
\tikzCenterNodes[name=toprow]{
(boc)/Basic Oxygen Converter,
(eaf)/Electric Arc Furnace}
\tikzCenterNodes[name=bottomrow, below=of toprow]{
(msc)/Medium Slab Casting,
(tsc)/Thick Slab Casting,
(bmc)/Bloom Casting,
(btc)/Billet Casting}
\path (eaf) edge coordinate (mid) (boc)
[ % half of node distance so
% that the horizontal part is halfway between nodes
vertical horizontal vertical, % to path = {|-|(\tikztotarget)}
ortho={distance=-.5*y_node_dist}
] (mid) edge (msc)
edge (tsc)
edge (bmc)
edge (btc);
\end{tikzpicture}
\end{document}