2

An example of the diagram I'm looking to create is:

basic-block diagram

I can get close to the desired output with the following tikz:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{intersections,shapes,arrows.meta,positioning}
\SetSymbolFont{letters}{bold}{OML}{cmbr}{bx}{it}
\renewcommand{\familydefault}{\sfdefault}

\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[
          line width=1.0pt
          , node distance=3cm
          , defblk/.style = {draw, rectangle, draw=black, minimum height=8cm, minimum width=1cm}
    ]

    \node[defblk, align=center](a){Block A};
    \node[defblk, right=of a](b){Block B};

    \draw[->] ([yshift=0 * -1cm]a.north east) -- node[above]{Signal 1} ([yshift=0 * -1cm]b.north west) ;
    \draw[->] ([yshift=1 * -1cm]a.north east) -- node[above]{Signal 2} ([yshift=1 * -1cm]b.north west) ;
    \draw[<-] ([yshift=2 * -1cm]a.north east) -- node[above]{Signal 3} ([yshift=2 * -1cm]b.north west) ;

    \draw[<-] ([yshift=4 * -1cm]a.north east) -- node[above]{Signal 4}([yshift=4 * -1cm]b.north west) ;
    \draw[<-] ([yshift=5 * -1cm]a.north east) -- node[above]{Signal 5}([yshift=5 * -1cm]b.north west) ;


\end{tikzpicture}
\end{document}

This is a fairly manual process though where re-arranging the connections requires me to re-type all the various offsets. What I'd like to do, is have the ability to incrementally specify nodes in the following way:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,shapes,arrows.meta,positioning}
\SetSymbolFont{letters}{bold}{OML}{cmbr}{bx}{it}
\renewcommand{\familydefault}{\sfdefault}

\begin{document}
\pagestyle{empty}

\begin{tikzpicture}[
          line width=1.0pt
          , node distance=3cm
          , defblk/.style = {draw, rectangle, draw=black, minimum height=8cm, minimum width=1cm}
    ]

    \node[defblk, align=center](a){Block A};
    \node[defblk, right=of a](b){Block B};

% This syntax below is pseudo-code that expresses how
% I'd like to incrementally specify paths
    \draw (a.north east) 
                    node[above, ->](sig1){Signal 1} -- ((sig1) -| (b.west))
        ++(0, -1cm) node[above, ->](sig2){Signal 2} -- ((sig2) -| (b.west))
        ++(0, -1cm) node[above, <-](sig3){Signal 3} -- ((sig3) -| (b.west))
        ++(0, -1cm) 
        ++(0, -1cm) node[above, <-](sig4){Signal 4} -- ((sig4) -| (b.west))
        ++(0, -1cm) node[above, <-](sig5){Signal 5} -- ((sig5) -| (b.west));

\end{tikzpicture}
\end{document}

After

Based off @marmot, the \foreach loop with the [count=\Z] option achieves what I'm looking for. A more detailed example is contained below:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}
\SetSymbolFont{letters}{bold}{OML}{cmbr}{bx}{it}
\renewcommand{\familydefault}{\sfdefault}

\begin{document}
\pagestyle{empty}

\begin{tikzpicture}[
          line width=1.0pt
          , node distance=3cm
          , rightof/.style = {right=of #1.north east, anchor=north west}
          , defblk/.style = {draw, rectangle, draw=black, minimum height=8cm, minimum width=1cm}
          , sig/.style = {above right, text width=2cm, align=left, black}
          , lvds/.style = {blue!80}
          , lvcmos/.style = {black}
    ]

    \node[defblk, align=center](a){Block A};
    \node[defblk, right=of a](b){Block B};

    \foreach \dir/\type/\name [count=\Z] in {
         ->/lvds/din clk
        ,->/lvds/din data
        ,->/lvds/din en
        ,->/lvds/din sync
        ,<-/lvds/din interrupt
        ,white//{}
        ,<-/lvds/dout clk
        ,<-/lvds/dout data
        ,<-/lvds/dout en
        ,white//{}
        ,<-/lvcmos/ctrl clk
        ,<-/lvcmos/ctrl data
        ,<-/lvcmos/ctrl en
    }
    {
        \def\ioff{-1em}
        \def\ispc{-1.5em}
        \draw[\dir, \type] ([yshift=\ioff + \Z*\ispc]a.north east) 
        node[sig]{\name} 
        -- 
        ([yshift=\ioff + \Z*\ispc]b.north west);
    }

\end{tikzpicture}
\end{document}

enter image description here

3

Welcome to TeX.SE! One way of shortening your code is to use a loop.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\SetSymbolFont{letters}{bold}{OML}{cmbr}{bx}{it}
\renewcommand{\familydefault}{\sfdefault}

\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[
          line width=1.0pt
          , node distance=3cm
          , defblk/.style = {draw, rectangle, draw=black, minimum height=8cm, minimum width=1cm}
    ]

    \node[defblk, align=center](a){Block A};
    \node[defblk, right=of a](b){Block B};
    \foreach \X/\Y [count=\Z] in {->/0,->/1,<-/2,<-/4,<-/5}
    {\draw[\X] ([yshift=\Y * -1cm]a.north east) -- node[above]{Signal \Z}
    ([yshift=\Y * -1cm]b.north west);}
\end{tikzpicture}
\end{document}

enter image description here

  • Great use of the \foreach loop -- the [count=\Z] magic is very helpful. Now I can add/remove signals without having to retype indices! – esimp Feb 6 at 10:51
2

huh, @marmot beat me for four minutes ... idea is the same, but realization is slightly different ...

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, positioning, quotes}
\renewcommand{\familydefault}{\sfdefault}

\begin{document}
    \begin{tikzpicture}[
node distance = 5mm and 30mm,
   line width = 1.0pt,
            > = Stealth,
defblk/.style = {rectangle, draw=black,
                 minimum height=4cm, minimum width=1cm,
                 outer sep=0pt},
    sy/.style = {yshift=#1 mm},
every edge quotes/.style = {anchor=south,inner sep=1pt, font=\footnotesize}
                    ]
\node[defblk]               (a) {Block A};
\node[defblk, right=of a]   (b) {Block B};
%
\coordinate[below=of a.north east] (sig1);
\foreach \i [count=\j] in {0,1,2, 4,5}
{\ifnum\j<3
    \draw[->]   ([sy=-\i*5] sig1) to ["Signal \j"] ([sy=-\i*5] sig1 -| b.west)
 \else
    \draw[<-]   ([sy=-\i*5] sig1) to ["Signal \j"] ([sy=-\i*5] sig1 -| b.west)
 \fi;
}
    \end{tikzpicture}
\end{document}

enter image description here

  • @Sebastiano, thank you. today i'm fast as a snail ... so i need more time to complete my answer and than give my tribute to marmot answer :-) – Zarko Feb 5 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.