6

I want to draw a Hypergraph using TikZ that looks like this

Connection Hypergraph

What I have so far:

\usepackage{tikz}
\usetikzlibrary{calc, positioning, fit, shapes.misc}

\begin{document}
\begin{tikzpicture}
[
    he/.style={draw, rounded corners},        % he = hyper edge
    ce/.style={draw, dashed, rounded corners} % ce = condition edge
]

\node (f) at (0,0) {$F$};
\node (g) at (1,0) {$G$};
\node (e) at (2,0) {$E$};
\node (d) at (2,1) {$D$};
\node (a) at (2,2) {$A$};
\node (b) at (3,2) {$B$};

\node [he, fit=(f) (g)] {};
\node [ce, fit=(g) (e)] {};
\node [he, fit=(a) (d) (e)] {};
\node [ce, fit=(a) (b) (d)] {};

\end{tikzpicture}
\end{document}

LaTeX Hypergraph

I didn't manage to ..

  • Make the hyperedges a little bit smaller like in the original picture, so that you can distinguish between hyperedges and condition edges
  • Make the ABD condition edge a triangle with rounded corners

Do you have any ideas how to do this? Furthermore, this is my first time working with TikZ, so if you have any other recommendations on how to improve the way of creating this graph and how to define styles, I would be happy to learn more.

  • you can give inner sep=0pt in style definition of he to make hyper edges smaller – nidhin Oct 28 '18 at 12:11
  • Thanks @nidhin. So far I tried to adjust the box sizes with scale, but inner sep works better. – ncw Oct 28 '18 at 12:16
8

You can change the inner sep of hyper edge or conditional edge so that they both will have different sizes.

I don't have a good solution for the second part using fit library. I just drew that conditional edge.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc, positioning, fit, shapes.misc}

\begin{document}
\begin{tikzpicture}
[
    he/.style={draw, rounded corners,inner sep=0pt},        % he = hyper edge
    ce/.style={draw,dashed, rounded corners=10pt}, % ce = condition edge
]

\node (f) at (0,0) {$F$};
\node (g) at (1,0) {$G$};
\node (e) at (2,0) {$E$};
\node (d) at (2,1) {$D$};
\node (a) at (2,2) {$A$};
\node (b) at (3,2) {$B$};

\node [he, fit=(f) (g)] {};
\node [ce, fit=(g) (e)] {};
\node [he, fit=(a) (d) (e)] {};
\node [fit=(a) (b) (d)] (fd){};
\draw [dashed,rounded corners=10pt] ($(fd.south west)+(0,-0.5)$) -- (fd.north west) -- ($(fd.north east)+(0.5,0)$)--cycle;
\end{tikzpicture}
\end{document}
  • I was just about to figure out how to draw a triangle around the nodes like you did, but I hard-coded the coordinates of the corners which is very tedious if I would ever want to add another triangle to the graph again. Your solution looks fine, thanks! – ncw Oct 28 '18 at 12:41

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.