Skip to content

Instantly share code, notes, and snippets.

@davidmdem
Created February 2, 2018 18:52
Show Gist options
  • Select an option

  • Save davidmdem/2ab3e47cfd7512ee2808e2f5ccc29166 to your computer and use it in GitHub Desktop.

Select an option

Save davidmdem/2ab3e47cfd7512ee2808e2f5ccc29166 to your computer and use it in GitHub Desktop.
Adjacency matrix in LaTex
\begin{wrapfigure}{r}{0.5\textwidth}
\centering
\caption{Adjacency List}
\begin{tikzpicture}[>=stealth]
\matrix (M) [matrix of nodes,%
column sep=-\pgflinewidth,%
row sep=1mm,%
nodes in empty cells,
nodes={draw, fill=gray!20,%
minimum width=.5cm, outer sep=0pt,%
minimum height=.7cm, anchor=center},
column 1/.style={nodes={minimum height=.8cm}}]%
{
&[2mm] C & &[2mm] L & / \\
& I & & U & / \\
& C & / \\
& D & & U & / \\
& F & & K & &[2mm] L & / \\
& E & & D & / \\
& F & / \\
& G & & D & / \\
& H & & J & & K & / \\
& B & & G & / \\
& B & & G & / \\
& A & & H & & J & / \\
& B & / \\
};
\foreach \v [count=\i] in {U,C,I,L,D,F,E,K,G,H,J,B,A} {
\path (M-\i-1) [late options={label=left:\v}];
\draw[->] (M-\i-1)--(M-\i-2.west);
}
\foreach \i in {1,2,4,5,6,8,9,10,11,12} {
\draw[->] (M-\i-3.center)--(M-\i-4.west);
}
\foreach \i in {5,9,12} {
\draw[->] (M-\i-5.center)--(M-\i-6.west);
}
\label{fig:adjacency}
\end{tikzpicture}
\end{wrapfigure}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment