4

I am currently working on a flow chart. The mwe (see below) produces the following output: flow chart as PDFLaTeX outputs it

How can I achieve the following, desired output, ideally without having to declare additional coordinates/nodes? I want the Casting nodes to be connected to the horizontal line between Basic Oxygen Converter and Electric Arc Furnace through a vertical line. Also, how can I center the whole group of Casting nodes relative to the nodes Basic Oxygen Converter and Electric Arc Furnace? flow chart as I want it to be

mwe

\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}

  • have you tried having a look at https://texample.net/tikz/examples/feature/trees/ I think it has some good templates for what you are after. – Paul A Oct 22 '22 at 13:25

2 Answers2

6

You can include your nodes into two different matrix nodes which can be easlily positioned one above the other. After that you just need to draw the links. I've used two auxiliary coordinates.

\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}

enter image description here

Ignasi
  • 136,588
4

Ignasi already explained how to use a \matrix, I'd recommend a more automatic way to place a bunch of nodes side-by-side by using the macro

\tikzCenterNodes[<options>]{list of <opt>/<text>}

which constructs a 1-row matrix with the <options> (this should be used for naming the matrix and placing it) and the nodes of the list, where <opt> is used between \node and the text <text> of the node.

I didn't add any safe-guarding in case only one node is used with \tikzCenterNodes but in that case you can use the normal \node macro.

Since you used the every node style (which also applies to the \matrix) I'm using the every outer matrix style to remove or reset a few default values for the matrix since we want it to be tightly fit around our row of nodes.


I'm using my libraries

  • ext.positioning-plus

    for the PGFMath functions x_node_dist and y_node_dist so that we don't have to give the node distance in one than more places (the horizontal node distance becomes the column sep value) and

  • ext.paths.ortho

    which allows us to use orthogonal connections of the form |-| (vertical horizontal vertical) where I again use y_node_dist so that the horizontal part of the |-| connection is halfway between the nodes.

This has one auxiliary coordinate mid that is halfway between the borders of the top two nodes.

Code

\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}

Output

enter image description here

Qrrbrbirlbel
  • 119,821