6

I try to present a part of a huge table inside the latex beamer environment. A small part of this table is sufficient to understand what is inside so i decided to indicate the cut-out be a bottom zig-zag line as shown below:

\begin{tikzpicture} 

\node(elenore)[minimum width=3cm, minimum height=1cm] 
at (0, 0) { 
\begin{tabular}{c| c c | l }
\cline{2-3}
 & \multicolumn{2}{c|}{comparison} &  \\
 \cline{1-4}
 \multicolumn{1}{|c|}{A} & B & C & \multicolumn{1}{l|} {value} \\
 \cline{1-4}
  \multicolumn{1}{|c|}{(1,\texttt{X},\texttt{\$},U,11)} & &   (\texttt{a},\texttt{\$},1) & \multicolumn{1}{l|}{C}]$} \\
  \multicolumn{1}{|c|}{(2,\texttt{r},1,10)} & (\texttt{O},1) & & 
  \multicolumn{1}{l|}{$H_{1} = [\texttt{aa}]$} \\
  \multicolumn{1}{|c|}{(3,\texttt{a},\texttt{a},3,2)} & & (\texttt{a},\texttt{a},6) & \multicolumn{1}{l|}{$H_5 = [\texttt{yyyyyy}]$} \\    
  \multicolumn{1}{|c|}{(4,\texttt{a},5,1)} & (\texttt{a},5) & &
  \multicolumn{1}{l|}{$H$ = [\texttt{text}]$} % \\ 
\end{tikzpicture} 
\draw[decoration={zigzag, mirror,segment length=6.25mm}, decorate] (elenore.south west) -- (elenore.south east); 

My Problem is: how can i stick the zig-zag line perfectly from the beginning of the very left table border to the very right one? Currently it overlaps a little bit what looks quite ugly. Any idea?

David Carlisle
  • 757,742
Daniel F
  • 539
  • 6
  • 14

2 Answers2

9

The extra padding you are getting is due to the value for node sep for the node containg the tabular; to get the desired result, you can simply set this to 0pt:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}

\begin{frame}
\centering
\begin{tikzpicture}[ampersand replacement=\&] 
\node[inner sep=0pt] (elenore)
{%
\begin{tabular}{| c | c c | l |} 
\cline{2-3}
\multicolumn{1}{c}{} & \multicolumn{2}{|c|}{Header} \\
\hline
A & B & C & D \\
E & F & G & H \\
I & J & K & L
\end{tabular}%
};
\draw[decoration={zigzag, mirror,segment length=6mm,amplitude=1.1pt}, decorate] 
  (elenore.south west) -- (elenore.south east);
 \end{tikzpicture} 
\end{frame}

\end{document}

enter image description here

Another option would be to draw everything (including the matrix itself) using TikZ:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc,matrix,decorations.pathmorphing}

\tikzset{ 
table/.style={
  matrix of nodes,
  row sep=-\pgflinewidth,
  column sep=-\pgflinewidth,
  nodes={rectangle,text width=3em,align=center},
  text depth=0.25ex,
  text height=1.5ex,
  nodes in empty cells
}
}

\begin{document}

\begin{frame}
\centering
\begin{tikzpicture}[ampersand replacement=\&] 
\matrix (elenore) [table] 
{ 
\& \& \& \\
A \& B \& C \& D \\
E \& F \& G \& H \\
I \& J \& K \& L \\
};
\node at ( $ (elenore-1-2)!0.5!(elenore-1-3) $ ) {Header};
\draw
  (elenore-1-2.south west) |- (elenore-1-3.north east) -- (elenore-1-3.south east);
\draw 
  (elenore-4-1.south west) |- (elenore-2-4.north east) -- (elenore-4-4.south east);
\draw[decoration={zigzag, mirror,segment length=6.25mm}, decorate] 
  (elenore-4-1.south west) -- (elenore-4-4.south east);
 \end{tikzpicture} 
\end{frame}

\end{document}

enter image description here

Just for the fun of it, here's another possibility using the pencildraw style designed by Ipsen in his answer to Torn page effect:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc,matrix,decorations.pathmorphing}

\tikzset{ 
table/.style={
  matrix of nodes,
  row sep=-\pgflinewidth,
  column sep=-\pgflinewidth,
  nodes={rectangle,text width=3em,align=center},
  text depth=0.25ex,
  text height=1.5ex,
  nodes in empty cells,
  column 4/.style={nodes={align=left}}
  },
pencildraw/.style={
    decorate,
    decoration={random steps,segment length=3pt,amplitude=1.5pt}
  }
}

\begin{document}

\begin{frame}
\centering
\begin{tikzpicture}[ampersand replacement=\&] 
\matrix (elenore) [table] 
{ 
\& \& \& \\
A \& B \& C \& D \\
E \& F \& G \& H \\
I \& J \& K \& L \\
};
\node at ( $ (elenore-1-2)!0.5!(elenore-1-3) $ ) {Header};
\draw
  (elenore-4-2.south west) |- (elenore-1-3.north east) -- (elenore-4-3.south east);
\draw 
  (elenore-4-1.south west) |- (elenore-2-4.north east) -- (elenore-4-4.south east);
\draw[pencildraw] 
  (elenore-4-1.south west) -- (elenore-4-4.south east);
 \end{tikzpicture} 
\end{frame}

\end{document}

enter image description here

Using

column <number>/.style={nodes={<options>}}

you can change the attributes for nodes in a column; for example, in the code above I used

 column 4/.style={nodes={align=left}}

to have text aligned left in the fourth column.

Moriambar
  • 11,466
Gonzalo Medina
  • 505,128
  • Nice! Is it possible to get the tabular layout {c| c c | l} back? Additionally i have to combine several columns as shown above so i need multicolumn. – Daniel F Jun 08 '13 at 23:47
  • @bobb_the_builder you can use \multicolumn directly, but my example shows a convenient replacement (see how "Header" was positioned simulating a \multicolumn). – Gonzalo Medina Jun 08 '13 at 23:51
  • @Gozalo Medina: both looks pretty good! But i'm still fighting with getting my "old" tabular layout back. I've never expected such an advanced solution as an answer to my quite "simple" question – Daniel F Jun 09 '13 at 00:02
  • 1
    @bobb_the_builder please see my updated answer, particularly the last remark about styles for columns. – Gonzalo Medina Jun 09 '13 at 00:06
  • @bobb_the_builder oops! A typo! In a comment before I wrote "you can use \multicolumn directly"; it should be "you cannot use \multicolumn directly". – Gonzalo Medina Jun 09 '13 at 00:11
  • @Gozalo Medina: yes, i noticed that, no problem. I think i undestood how it works, very good so far. As a little note: it seems that the arydshln package supports "whatever styled" \cline arguments .. that would be also a choice – Daniel F Jun 09 '13 at 00:23
  • @bobb_the_builder please see my updated answer. At the beginning of my edit I've included an option allowing you to use your initial settings (a tabular inside a \node). – Gonzalo Medina Jun 09 '13 at 01:29
6

You don't have to use tikz

enter image description here

Your tabular example markup generated a lot of errors so I had to make a few guesses as to the intended cells, but something like

\documentclass{beamer}

\begin{document}

\begin{frame}

\sbox0{\begin{tabular}[b]{c| c c | l }
\cline{2-3}
 & \multicolumn{2}{c|}{comparison} &  \\
 \cline{1-4}
 \multicolumn{1}{|c|}{A} & B & C & \multicolumn{1}{l|} {value} \\
 \cline{1-4}
  \multicolumn{1}{|c|}{(1,\texttt{X},\texttt{\$},U,11)} & &   (\texttt{a},\texttt{\$},1) & \multicolumn{1}{l|}{C} \\
  \multicolumn{1}{|c|}{(2,\texttt{r},1,10)} & (\texttt{O},1) & & 
  \multicolumn{1}{l|}{$H_{1} = [\texttt{aa}]$} \\
  \multicolumn{1}{|c|}{(3,\texttt{a},\texttt{a},3,2)} & & (\texttt{a},\texttt{a},6) & \multicolumn{1}{l|}{$H_5 = [\texttt{yyyyyy}]$} \\    
  \multicolumn{1}{|c|}{(4,\texttt{a},5,1)} & (\texttt{a},5) & &
  \multicolumn{1}{l|}{$H = [\texttt{text}]$}\\
\multicolumn{1}{c}{}
\end{tabular}}%
\usebox0\llap{\resizebox{\wd0}{\height}{\fboxsep0pt\colorbox{white}{\strut${\sim}\!{\sim}\!{\sim}$}}}
\end{frame}
\end{document}
David Carlisle
  • 757,742
  • thanks for the correction and for the short,tikz-free solution! The knotted lines are funny looking! I will simply pocket your idea! :-) – Daniel F Jun 09 '13 at 00:54