我尝试在 latex beamer 环境中展示一张巨大桌子的一部分。这张桌子的一小部分足以让我们了解里面的内容,因此我决定用底部的锯齿线来表示切口,如下所示:
\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);
我的问题是:如何才能完美地将锯齿线从最左侧表格边框的起点粘贴到最右侧表格边框?目前它有点重叠,看起来相当丑陋。有什么想法吗?
答案1
您获得的额外填充是由于node sep
包含的节点的值tabular
;为了获得所需的结果,您只需将其设置为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}
另一种选择是使用 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}
只是为了好玩,这里还有另一种使用pencildraw
由设计的样式的可能性益普生在his answer
到撕页效果:
\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}
使用
column <number>/.style={nodes={<options>}}
您可以更改列中节点的属性;例如,在上面的代码中我使用了
column 4/.style={nodes={align=left}}
使文本在第四列左对齐。
答案2
你不需要有使用 tikz
您的表格示例标记产生了很多错误,所以我不得不对预期的单元格做出一些猜测,但类似
\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}