I am a beginner in TikZ. I want to draw a simple network with 2 nodes and a network like this:


My code is here:

\usetikzlibrary{arrows, shapes, trees, calc}

% Define styles
\tikzstyle{bnode}=[draw, fill=blue!20, text width=5em, text centered, minimum height=2.5em]


    % draw two nodes
    \node (node1) [bnode] at (0, 0) {Node 1};
    \node (node2) [bnode] at (4, 0) {Node 2};

    % draw network

    % name this line to line1
    \draw[line width=2pt] ($(node1.west |- node1.south)+(0, -.5)$) -- ($(node2.east |- node2.south)+(0, -.5)$);
    % and draw a line between node1 and line1 like this:
    % \draw[line width=2pt] (node1) -- (line1); 

    \draw[line width=2pt] (node1) -- (0, -.95);
    \draw[line width=2pt] (node2) -- (4, -.95);


I made the horizontal line drawn by the position of Node1 and Node2, but I don't know how to draw a relative vertical line. Can you help optimize the code?

1 Answer 1


Something like this? I'm not sure if it is optimised or not - it probably depends what you have in mind.

\tikzset{% \tikzstyle is deprecated
  bnode/.style={draw, fill=blue!20, text width=5em, text centered, minimum height=2.5em, line width=.4pt, above=.95}}
  \path [draw, line width=2pt] (0,0) coordinate (o) node (node 1) [bnode, anchor=west] {Node 1} -- (6,0) node (node 2) [bnode, anchor=east] {Node 2} (o -| node 1.south) -- (node 1.south) (o -| node 2.south) -- (node 2.south);


  • Thank you cfr, This is what I wanted. It is working well but I need to study TikZ more.. Nov 10, 2015 at 4:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .