0

I want to draw a block diagram using blocks that have one input and two outputs. To position them nicely, I would like to define anchor points for these outputs.

Block with one inputs and two outputs

how would I define something like this?

I defined the block like this

\tikzstyle{block} = [draw, rectangle, 
minimum height=4em, minimum width=5em, align=center]

Then I wanted to place two blocks and connect the first output of the first block with the input of the second block, that the line if perfectly straight, something like this:

\draw
node at (0,0) [block] (A) {}
node at (6,1) [block] (B) {};
\draw [->] (A.output1) -- node {} (B.input);

Can I somehow define the points A.output1, A.output2 and B.input?

Thanks!

cedi123
  • 31

1 Answers1

3

Adopting [1] and [2] we can do this.

The input anchor is just an alias for west while the output 1/2 and output 2/2 anchors are measured a third and two thirds between the north east and the north west anchor.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\makeatletter
\pgfset{
  alias anchor/.code 2 args=\pgfdeclaregenericanchor{#1}{\pgf@sh@reanchor{##1}{#2}},
  generate anchors'/.code n args={4}{%
    \pgfmathloop\pgfmathparse{\pgfmathcounter/(#2+1)}%
      \pgfset{generate anchor/.expanded={#1 \pgfmathcounter/#2}:{\pgfmathresult}:{#3}:{#4}}%
      \ifnum\pgfmathcounter<#2\relax\repeatpgfmathloop},
  generate anchor/.code args={#1:#2:#3:#4}{%
    \pgfdeclaregenericanchor{#1}{%
      \pgfpointlineattime{#2}{\pgf@sh@reanchor{##1}{#3}}{\pgf@sh@reanchor{##1}{#4}}}},
  generate anchors/.style n args={3}{
    /utils/tempa/.style={/pgf/generate anchor={##1:#2:#3}}, /utils/tempa/.list={#1}}}
\makeatother
\pgfset{
  alias anchor={input}{west},
  generate anchors'={output}{2}{north east}{south east}}
\begin{document}
\begin{tikzpicture}[
  block/.style={
    draw, rectangle, minimum height=4em, minimum width=5em, align=center},
]
\node[block]                                      (A) {}
 node[block, right=of A.output 2/2, anchor=input] (B) {};
\draw[->] (A.output 2/2) -- (B.input);
\draw[->] (A.output 1/2) -- +(right:.5);
\draw[<-] (A.input) -- +(left:.5);
\end{tikzpicture}
\end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821
  • If you really want input 1 instead of input 1/2 while other nodes possibly have more (or different ones) than those two, more work is necessary. – Qrrbrbirlbel Sep 19 '23 at 15:31