COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Draw an adjacency-list representation of a graph with tikz

• Follow

Hello.

I would like to draw the adjacency-list representation of a graph
using tikz, but I do not master it yet.

The picture should look like the one found at

Any help?

Romildo

 0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

romildo <j.romildo@gmail.com> writes:

> Hello.
>
> I would like to draw the adjacency-list representation of a graph
> using tikz, but I do not master it yet.
>
> The picture should look like the one found at
Are you sure that this is possible (i.e. already implemented)?

- --
- --

It is better to die on one's feet than live on one's knees.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAkx2qxQACgkQM0LLzLt8Mhx18QCghCRlS/Vrr9ImIqxQHZK65jP2
OCUAni0slSwhqrv/Y3P85E91tEdG7PvN
=tAVV
-----END PGP SIGNATURE-----

 0

On Aug 25, 9:23=A0pm, romildo <j.romi...@gmail.com> wrote:

Try this:

%------------------------
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength{\PreviewBorder}{5mm}
\pagestyle{empty}

\begin{document}
\thispagestyle{empty}
\begin{tikzpicture}
\matrix (M) [matrix of nodes,
column sep=3D0pt,
row sep=3D0pt,
nodes=3D{draw,fill=3Dgray!20,minimum width=3D.5cm,outer sep=3D0pt,minimum
height=3D.7cm,anchor=3Dcenter},
column 1/.style=3D{minimum height=3D.8cm}]{
\mbox{} &[2mm] 2 & \mbox{} &[2mm] 5 & $/$  &[2mm]   &   &[2mm]   & \\
\mbox{} & 1 & \mbox{} & 5 & \mbox{}  & 3 &  \mbox{} & 4 & $/$  \\
\mbox{}  & 2 & \mbox{} & 4 & $/$  &   &   &   & \\
\mbox{} & 2 & \mbox{} & 5 & \mbox{}  & 3 & $/$  &   & \\
\mbox{} & 4 & \mbox{} & 1 & \mbox{}  & 2 & $/$  &   & \\
};
\foreach \i in {1,2,3,4,5}{
\path (M-\i-1) [late options=3D{label=3Dleft:\i}];
\draw[->] (M-\i-1.center)--(M-\i-2.west);
\draw[->] (M-\i-3.center)--(M-\i-4.west);
}
\draw[->] (M-2-5.center)--(M-2-6.west);
\draw[->] (M-4-5.center)--(M-4-6.west);
\draw[->] (M-5-5.center)--(M-5-6.west);
\draw[->] (M-2-7.center)--(M-2-8.west);
\end{tikzpicture}
\end{document}
%-------------------------

Ignasi

 0

2 Replies
1095 Views