Is there a simple way to align the following two sets of the bipartite graph horizontally, i.e. move the three nodes on the left 1.5 times the vertical node distance downwards?

enter image description here

\graph[grow right sep=2cm,empty nodes,nodes={fill,circle,inner sep=0,minimum size=2mm}] {
    subgraph K_nm [n=3,m=6]

With use of the chains library, nodes on grid, defined lenght for calculating neurons distances.

Minimal working example (MWE):

node distance = \ND, on grid,
  start chain = going below,
neuron/.style = {circle,draw, fill, minimum size=5pt, inner sep=0pt,
                 on chain, node contents={}},
\setlength\ND{8mm}    % Nuuron Distance
% left neurons
\foreach \i in {1,2,3}
    \node (n1\i) [neuron];
% right neurons
    \node (n21) [neuron, above right=1.5\ND and 4*\ND of n11];
\foreach \i in {2,...,6}
    \node (n2\i) [neuron];
% Connect every input newrons with every output one
\foreach \i in {1,...,3}
    \foreach \j in {1,...,6}
    \draw (n1\i) -- (n2\j);

enter image description here


enter image description here

\usetikzlibrary{positioning,arrows.meta,shapes,shapes.multipart, positioning, decorations.markings,arrows.meta, calc, fit}
    node distance=\layersep,
    neuron/.style={circle,fill=black!25,minimum size=5pt,inner sep=0pt},
    input neuron/.style={neuron, fill=red!50},
    output neuron/.style={neuron, fill=orange!50},
    hidden neuron/.style={neuron, fill=green!50},
    % Draw the input layer nodes
    \foreach \name / \y in {1,...,3}
    % This is the same as writing \foreach \name / \y in {1/1,2/2,3/3,4/4}
    \node[input neuron] (I-\name) at (0,-\y) {};
    % Draw the hidden layer nodes
    \foreach \name / \y in {1,...,6}
    node[hidden neuron] (H-\name) at (\layersep,-\y cm) {};    
    %       % Connect every node in the input layer with every node in the
    %       % hidden layer.
    \foreach \source in {1,...,3}
    \foreach \dest in {1,...,6}
    \path (I-\source) edge (H-\dest);
  • 2
    Thank you for the help! Though, it seems there's no easier way with an option, right?
    – Xiphias
    Apr 5 '21 at 16:08

There is an easy way using layered layout:

% !TeX program = lualatex


\tikz \graph[empty nodes,
    layered layout, % <- new
    level distance=2cm, % <- new
    grow=right, % <- new
    nodes={fill,circle,inner sep=0,minimum size=2mm}]
    {subgraph K_nm [n=3,m=6]};


In this case you don't need to calculate anything, that work is left to layered.

Here is minimal example where you can compare its usage:

\tikz \graph[layered layout,grow=right] {a -- {b,c}};
\tikz \graph {a -- {b,c}};

minimal example comparation

  • Great, thank you!
    – Xiphias
    Jul 25 '21 at 15:10

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.