[Tex/LaTex] Tabular with arrows or lines between some cells

tablestikz-pgf

I have a table like the one below and want to write this in Latex. what would be the best aproach? I have tried it with Tikz where i can nest a Table but failed with the lines wich connect the different fields. Another solution would be to use a tikz tree, but there i don't know how to label the edges.

Is it possible to create something like this with an easy markup, either in TikZ or with any other latex package?

Huffman Coding

Best Answer

Here is a beginning of a solution with tikz matrixenter image description here

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{matrix}


\begin{document}

\begin{tikzpicture}
[every node/.style={minimum height=2em}]
\matrix [matrix of math nodes](Mat)
{
x_i  &|[minimum width=4em]|& P(x_i) &|[minimum width=4em]| Code &       &|[minimum width=4em]|      &       &|[minimum width=4em]|  &   &|[minimum width=4em]|  &   &\\
x_1 &&0.30     &        & 0.30  &   &0.30   &   &0.45&  &0.55&\\
x_2 && 0.25    &        & 0.25  &   &0.25   &   &0.30&  &0.45&\\
x_3 && 0.20   &     & 0.20  &   &0.25   &   &0.25&  &   &\\
x_4 && 0.12    &        &0.13   &   &0.20   &   &   &   &   &\\
x_5 && 0.08    &        &0.12   &   &       &   &   &   &   &\\
x_6 && 0.05    &        &   &   &       &   &   &   &   &\\
};

\draw (Mat-2-3.east) -- (Mat-2-3-|Mat-2-5.west)node[above,midway]{00};
\draw(Mat-5-3.east) --++(1em,0) -- (Mat-6-5.west)node[above,pos=0.2]{101};
\draw (Mat-6-3.east)-|node[above,pos=0.4]{1000}++(2em,-1em) coordinate(aa) --++(1em,0) |- (Mat-5-5.west);
\draw (Mat-7-3.east)-|node[below,pos=0.4]{1001} (aa);
\end{tikzpicture}

\end{document}
Related Question