In the following tree, some nodes have multiple parents (which technically violates the tree definition).

Tree with multiple parent nodes

Therefore, to create the tree in the forest package, I manually added the edges from children to (additional) parents. However, the nodes are now unevenly spaced due to forest thinking that each node belongs to one parent at most.

My question is now how to evenly horizontally distribute the nodes over each level so that, for example, the bottom node {a,b,c,d} is centered.

Here is my code so far:


  for tree={
    inner sep=1.5pt,
          [$\{a{,}b{,}c{,}d\}$,name=abcd ]
        [$\{a{,}b{,}d\}$,name=abd ]
        [$\{a{,}c{,}d\}$,name=acd ]
      [$\{a{,}d\}$,name=ad ]
        [$\{b{,}c{,}d\}$,name=bcd ]      
      [$\{b{,}d\}$,name=bd ]
      [$\{c{,}d\}$,name=cd ]
  \draw (b) edge (ab);
  \draw (c) edge (ac);
  \draw (c) edge (bc);
  \draw (d) edge (ad);
  \draw (d) edge (bd);
  \draw (d) edge (cd);
  \draw (ac) edge (abc);
  \draw (bc) edge (abc);
  \draw (ad) edge (abd);
  \draw (bd) edge (abd);
  \draw (ad) edge (acd);
  \draw (cd) edge (acd);
  \draw (bd) edge (bcd);
  \draw (cd) edge (bcd);
  \draw (abd) edge (abcd);
  \draw (acd) edge (abcd);
  \draw (bcd) edge (abcd);

Thanks in advance for your help!

  • 3
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – jlab
    Commented Apr 2 at 11:51
  • 3
    It looks like a Hasse diagram, is it really needed the forest environment? If not, it can be done with node placing and edges (this question, or this question can be helpful) or with the tikz-cd package, if you need something fast, but without ellipses (check quiver for this) Commented Apr 2 at 12:50
  • 1
    You can do this with forest, but it may be overkill. Forest tries hard to avoid edges crossing. (It sometimes loses track, but that's the aim.) That seems beside the point here? A matrix of math nodes might make more sense, even.
    – cfr
    Commented Apr 2 at 16:16

2 Answers 2


As Lorenzo and cfr pointed out, using the forest package does not seem to be the easiest approach here. Instead, I solved the problem by manually creating the Hasse diagram (thanks again to Lorenzo) similar to this question using TikZ:

Tree with evenly spaced nodes

Here is my code:



\begin{tikzpicture}[scale=0.7,inner sep=2]
 \node[ellipse,draw=black](0) at (-3,10) {$\O$};

 \node[ellipse,draw=black](a) at (-7.5,8) {$\{a\}$};
 \node[ellipse,draw=black](b) at (-4.5,8) {$\{b\}$};
 \node[ellipse,draw=black](c) at (-1.5,8) {$\{c\}$};
 \node[ellipse,draw=black](d) at (1.5,8) {$\{d\}$};

 \node[ellipse,draw=black](ab) at (-10.5,6) {$\{a{,}b\}$};
 \node[ellipse,draw=black](ac) at (-7.5,6) {$\{a{,}c\}$};
 \node[ellipse,draw=black](ad) at (-4.5,6) {$\{a{,}d\}$};
 \node[ellipse,draw=black](bc) at (-1.5,6) {$\{b{,}c\}$};
 \node[ellipse,draw=black](bd) at (1.5,6) {$\{b{,}d\}$};
 \node[ellipse,draw=black](cd) at (4.5,6) {$\{c{,}d\}$};

 \node[ellipse,draw=black](abc) at (-9.75,4) {$\{a{,}b{,}c\}$};
 \node[ellipse,draw=black](abd) at (-5.25,4) {$\{a{,}b{,}d\}$};
 \node[ellipse,draw=black](acd) at (-0.75,4) {$\{a{,}c{,}d\}$};
 \node[ellipse,draw=black](bcd) at (3.75,4) {$\{b{,}c{,}d\}$};

 \node[ellipse,draw=black](abcd) at (-3,2) {$\{a{,}b{,}c{,}d\}$};

 \draw (0) -- (a);
 \draw (0) -- (b);
 \draw (0) -- (c);
 \draw (0) -- (d);
 \draw (a) -- (ab);
 \draw (a) -- (ac);
 \draw (a) -- (ad);
 \draw (b) -- (ab);
 \draw (b) -- (bc);
 \draw (b) -- (bd);
 \draw (c) -- (ac);
 \draw (c) -- (bc);
 \draw (c) -- (cd);
 \draw (d) -- (ad);
 \draw (d) -- (bd);
 \draw (d) -- (cd);
 \draw (ab) -- (abc);
 \draw (ab) -- (abd);
 \draw (ac) -- (abc);
 \draw (ac) -- (acd);
 \draw (ad) -- (abd);
 \draw (ad) -- (acd);
 \draw (bc) -- (abc);
 \draw (bc) -- (bcd);
 \draw (bd) -- (abd);
 \draw (bd) -- (bcd);
 \draw (cd) -- (acd);
 \draw (cd) -- (bcd);
 \draw (abc) -- (abcd);
 \draw (abd) -- (abcd);
 \draw (acd) -- (abcd);
 \draw (bcd) -- (abcd);

  • 2
    Suggestion: You can (and should) refactor the node style, which doesn't change. I.e. move it to the beginning, give the style a name and simplify the node options.
    – MS-SPO
    Commented Apr 2 at 17:04

I think a matrix of math nodes would be easier (and faster!) than forest, which tries to avoid crossing edges. For example,

% ateb: https://tex.stackexchange.com/a/714619/
  \matrix (h) [matrix of math nodes,row sep=10mm,column sep=-10pt,nodes={text width=15mm,align=center,inner xsep=0pt,ellipse,draw}]
    &&&&& \O  \\
    & \{a\} && \{b\} &&&& \{c\} && \{d\}  \\
    \{a,b\} && \{a,c\} && \{a,d\} && \{b,c\} && \{b,d\} && \{c,d\} \\
    & \{a,b,c\} && \{a,b,d\} &&&& \{a,c,d\} && \{b,c,d\} \\
    &&&&& \{a,b,c,d\}\\
  \foreach \j in {2,4,8,10}
    \draw  (h-1-6.south) -- (h-2-\j.north);
    \draw  (h-4-\j.south) -- (h-5-6.north);
  \foreach \j in {1,3,5} \draw (h-2-2.south) -- (h-3-\j.north);
  \foreach \j in {5,9,11} \draw (h-2-10.south) -- (h-3-\j.north);
  \foreach \j in {1,7,9} \draw (h-2-4.south) -- (h-3-\j.north);
  \foreach \j in {3,7,11} \draw (h-2-8.south) -- (h-3-\j.north);
  \foreach \j in {1,3,7} \draw (h-4-2.north) -- (h-3-\j.south);
  \foreach \j in {1,5,9} \draw (h-4-4.north) -- (h-3-\j.south);
  \foreach \j in {3,5,11} \draw (h-4-8.north) -- (h-3-\j.south);
  \foreach \j in {11,9,7} \draw (h-4-10.north) -- (h-3-\j.south);

[Image omitted due to Okular bug.]

From community:


[Note that I forgot the ellipse and 'community' was too quick, so the image doesn't draw the ellipse, even though the code does!]

You must log in to answer this question.

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