4

How can I draw the following in Latex? enter image description here

I have created the two tables, but I can't figure out how to draw the lines among the cells.

4

It's possible to reproduce the whole composition with two TiKZ matrices:

enter image description here

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix, positioning}

\begin{document}
\begin{tikzpicture}[
mycell/.style={draw, minimum size=7mm, fill=gray!30},
matrixA/.style={matrix of nodes,
    nodes={mycell, anchor=center},
    column sep=-\pgflinewidth, 
    row sep=-\pgflinewidth, 
    row 1/.style={nodes={draw=none, fill=none}},
    row 2/.style={font=\slshape}},
matrixB/.style={matrix of nodes,
    nodes={mycell, anchor=center},
    column sep=-\pgflinewidth, 
    row sep=-\pgflinewidth, 
    row 3/.style={nodes={draw=none, anchor=base, fill=none}, font=\slshape},
}]

\matrix[matrixA] (A) {
|[label=180:edge]| 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 & 19 & 21 & 21 & 22 & 23\\
|[label={[font=\rmfamily]180:destination}]| b & d & e & a & c & e & b & e & g & a & e & f & a & b & c & d & f & g & d & e & g & c & e & f \\
|[label=180:weight]| 4 & 12 & 9 &  4 & 8 & 7 & 8 & 5 & 2 & 12 & 3 & 6 & 9 & 7 & 5 & 3 & 1 & 13 & 6 & 1 & 11 & 2 & 13 & 11\\};

\matrix[matrixB, below=of A] (B) {
|[label=180:first edge]| 0 & 3 & 6 & 9 & 12 & 18 & 21\\
|[label=180:outdegree]| 3 & 3 & 3 & 3 & 6 & 3 & 3\\
|[label={[font=\rmfamily]180:vertex}]| a & b & c & d & e & f & g\\};

\foreach \i [count=\j] in {1, 4, 7, 10, 12, 18, 21} 
\draw (A-3-\i.south west)--(B-1-\j.north west);
\draw (A-3-23.south east)--(B-1-7.north east);

\end{tikzpicture}
\end{document}
  • one more question. how can I resize the tikzpicture? I tried to do that with resizebox but it does not work. – Arshak Mehrabyan Jul 26 '16 at 12:04
  • @ArshakMehrabyan: If you want to include a tikzpicture (which includes matrix) inside a resizebox command you need to apply ampersand replacement option. See: this answer. A second solution would be to use standalone class to obtain a cropped figure and include it in your text with \includegraphics command. – Ignasi Jul 26 '16 at 12:23
  • thank you again @ignasi. I fixed it with ampersand replacement. – Arshak Mehrabyan Jul 26 '16 at 13:27

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.