Skip to content

Instantly share code, notes, and snippets.

@keyan
Created January 12, 2020 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keyan/f2be9b435faef9dcfdb1446fa6bbd1a9 to your computer and use it in GitHub Desktop.
Save keyan/f2be9b435faef9dcfdb1446fa6bbd1a9 to your computer and use it in GitHub Desktop.
Drawing matching graphs in Latex

First include the graph drawing library tkz-berge by adding it the the \usepackage directive in the document preamble.

The follow code block produces this graph of a simple stable matching:

matching

\begin{tikzpicture}[]
\GraphInit[vstyle=Normal]
    \SetUpVertex[Math,Lpos=-180,LabelOut]
    \Vertex[x=0,y=2,LabelOut=true]{A_{1,2}}
    \Vertex[x=0,y=1,LabelOut=true]{B_{1,2}}
    \SetUpVertex[Lpos=0]
    \Vertex[x=6,y=2,LabelOut=true]{1_{A,B}}
    \Vertex[x=6,y=1,LabelOut=true]{2_{A,B}}
    \SetUpEdge[lw=1pt,color=black]
    \Edge[](A_{1,2})(1_{A,B})
    \Edge[](B_{1,2})(2_{A,B})
\end{tikzpicture}

You can also modify the edge labels to add weights (helpful for question 5b), adding the follow label produces this graph:

weighted

    \Edge[label=$1$,style={pos=0.25}](A_{1,2})(1_{A,B})
    \Edge[label=$1$,style={pos=0.75}](B_{1,2})(2_{A,B})

If you want to customize this further you can peruse the (definitely incomplete) docs: http://ctan.math.illinois.edu/macros/latex/contrib/tkz/tkz-berge/doc/tkz-berge-screen.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment