我正在尝试让一个节点适合表格环境中的表格中的所有单元格,但似乎 tikz 只能在我的文档中的当前单元格内工作,并且在最小示例中,它显示了覆盖表格一半的更奇怪的东西,然后当我再次编译它时,它又回到仅在最后一个单元格内工作的状态。有点困惑。以下文档或多或少显示了我想要的内容:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{decorations, calc, fit}
\usepackage{multirow}
\begin{document}
\begin{frame}
\frametitle{Anatomía de la representación tabular}
\def\arraystretch{2}\tabcolsep=10pt
\begin{table}
\caption {Título de la tabla}
\begin{tabular}{c|ccc}
\multirow{2}{1.5cm}{Columna Princpial} & \multicolumn{2}{c}{Columna 2} & \multirow{2}{2cm}{Columna 3} \\[0.5\baselineskip]
& Sub 1 & Sub 2 & \\
\hline
Categoría 1 & \tikz{ \node[remember picture, anchor=base,inner sep=0pt, draw] (celda1) {Celda}; } & Celda & Celda \\
Categoría 2 & Celda & Celda & \tikz{ \node[remember picture, anchor=base,inner sep=0pt, draw] (celda2) {Celda}; }
\tikz{
\node [remember picture, draw = red, fit = (celda1) (celda2), overlay] {};
}
\end{tabular}
\\[0.5\baselineskip]
Origen de la tabla \\
Notas al pie
\end{table}
\end{frame}
\end{document}
我究竟做错了什么?
答案1
需要TiKZ
的remember
是整体情况而不仅仅是一些nodes
。remember picture
必须将选项应用于\tikz
命令或tikzpicture
环境:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{decorations, calc, fit}
\usepackage{multirow}
\begin{document}
\begin{frame}
\frametitle{Anatomía de la representación tabular}
\def\arraystretch{2}\tabcolsep=10pt
\begin{table}
\caption {Título de la tabla}
\begin{tabular}{c|ccc}
\multirow{2}{1.5cm}{Columna Princpial} & \multicolumn{2}{c}{Columna 2} & \multirow{2}{2cm}{Columna 3} \\[0.5\baselineskip]
& Sub 1 & Sub 2 & \\
\hline
Categoría 1 & \tikz[remember picture]{ \node[anchor=base,inner sep=0pt, draw] (celda1) {Celda}; } & Celda & Celda \\
Categoría 2 & Celda & Celda & \tikz[remember picture]{ \node[anchor=base,inner sep=0pt, draw] (celda2) {Celda}; }
\tikz[remember picture,overlay]{
\node [draw = red, fit = (celda1) (celda2)] {};
}
\end{tabular}
\\[0.5\baselineskip]
Origen de la tabla \\
Notas al pie
\end{table}
\end{frame}
\end{document}