1

I'm trying to get a node to fit all the cells in a table inside a tabular environment, but it seems tikz can only work inside the current cell in my document and in the minimal example it showed something even weirder covering half the table, then when I compiled it again it went back to working only inside the last cell. Kind of confused here. The following document shows more or less what I would want:

\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}

What am I doing wrong?

2

What TiKZ needs to remember is the whole picture and not only some nodes. remember picture option must be applied to \tikz command or tikzpicture environment:

\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}

enter image description here

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.