1

I want a rounded box around the number 3480 on slide 2. The box is there in slide 1. I have used the same format along with uncover in slide 2. But I am not getting the box. Please look into the code and let me know the mistake. Also, is there any easier way to draw boxes around text when using uncover?

\documentclass[notes,11pt, aspectratio=169]{beamer}
\usepackage{pgfpages}
\usepackage{helvet}
\usepackage[default]{lato}
\usepackage{array}
\usepackage{tikz}
\usepackage{verbatim}
\setbeamertemplate{note page}{\pagecolor{yellow!5}\insertnote}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\usetikzlibrary{arrows}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shapes.misc}
\usetikzlibrary{matrix,shapes,arrows,fit,tikzmark}
\usepackage{amsmath}
\usepackage{mathpazo}
\usepackage{hyperref}
\usepackage{lipsum}
\usepackage{multimedia}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage[space]{grffile}
\usepackage{booktabs}
\begin{document}
    
    %%% TIKZ STUFF
    \tikzset{   
        every picture/.style={remember picture,baseline},
        every node/.style={anchor=base,align=center,outer sep=1.5pt},
        every path/.style={thick},
    }
    \newcommand\marktopleft[1]{%
        \tikz[overlay,remember picture] 
        \node (marker-#1-a) at (-.3em,.3em) {};%
    }
    \newcommand\markbottomright[2]{%
        \tikz[overlay,remember picture] 
        \node (marker-#1-b) at (0em,0em) {};%
    }
    \tikzstyle{every picture}+=[remember picture] 
    \tikzstyle{mybox} =[draw=black, very thick, rectangle, inner sep=10pt, inner ysep=20pt]
    \tikzstyle{fancytitle} =[draw=black,fill=red, text=white]
    %%%% END TIKZ STUFF


\begin{frame}{Slide 1}
    \makebox[\linewidth][c]{
        \begin{tabular}{l cc ccc}
            \toprule
            &  Mean at && \multicolumn{3}{c}{Difference-in-Differences Estimates} \\
            \cmidrule{4-6}
            & $ t=-1 $ &&\multicolumn{1}{c}{1 Year} & \multicolumn{1}{c}{2 Years} & \multicolumn{1}{c}{3 Years} \\
            \cmidrule{2-2} \cmidrule{4-6}
            & \multicolumn{1}{c}{(1)}  &&\multicolumn{1}{c}{(2)} & \multicolumn{1}{c}{(3)} & \multicolumn{1}{c}{(4)} \\
            \cmidrule{2-6}
            Outcome 1 & 2.58 && 0.11 &0.08 &\marktopleft{a1} 0.12\\
            & (2.55) && (0.04) & (0.04) & (0.04)\\ 
            Outcome 2 & 60.90 && -0.73 &-1.13 & -1.58\\
            & (17.02) && (0.10) & (0.11) & (0.12)\markbottomright{a1}{red} \\
            Outcome 3 & 18.98 && 0.77 &1.28 & 1.62\\
            & (6.74) && (0.13) & (0.13) & (0.12)\\ 
            \bottomrule
        \end{tabular}
    }
    \uncover<2->{\tikz[overlay,remember picture,inner sep=1pt]
        \node[draw=red,rounded corners,fit=(marker-a1-a.north west) (marker-a1-b.south east)] {};}
\end{frame}

\begin{frame}{Highlight the minimum cost cell using tikz (Slide 2)}
    \begin{itemize}[<alert@+|+->]
        \item[] \begin{table}
        \centering
        \resizebox{\linewidth}{!}{
            \begin{tabular}{ c | c | c | c | c | c  }
                \toprule
                Order quantity & Unit price & Annual OC & Annual HC & Annual product cost & Total annual cost\\
                \midrule
                840 & \uncover<+->{$\$0.85$} & \uncover<+->{10} & \uncover<+->{30} & \uncover<+->{50} & \uncover<+->{\$3686} \\
            \midrule
            1000 & \uncover<+->{$\$0.80$} & \uncover<+->{20} & \uncover<+->{40} & \uncover<+->{45} & \uncover<+->{ \marktopleft{a1} \$3480 \markbottomright{a1}{red}} \\
                \bottomrule
            \end{tabular}
        }
    \end{table}
    \end{itemize}   
    \uncover<+->{\tikz[overlay,remember picture,inner sep=1pt]
    \node[draw=red,rounded corners,fit=(marker-a1-a.north west) (marker-a1-b.south east)] {};}
\end{frame}

\end{document}
3
  • Please remove all packages, not needed to show your problem, when compiled. Thank you
    – MS-SPO
    Commented Feb 9 at 8:48
  • 2
    The box is there, to the right, where the table entry would be without the \resizebox command. Remove \resizebox and choose a smaller fontsize instead, like {\footnotesize\begin{tabular}...\end{tabular}}. Moreover, you probably don't want the table as an item, as items are indented, counteracting the centering you apparently want to achieve with \centering.
    – gernot
    Commented Feb 9 at 9:07
  • Thanks. The suggestion is helpful. I want the table to appear after some content in the start of the slide. That is why I had put it as item. When I am using it without item, the table is always there on the slide. How can I make it appear after some content without using itemize?
    – mathslove
    Commented Feb 9 at 10:39

1 Answer 1

2

You could use the hf-tikz package to highlight a number on certain overlays:

\documentclass[11pt, aspectratio=169]{beamer}

\usepackage{booktabs}
\usepackage{tikz}
\usepackage[beamer,customcolors]{hf-tikz}

\hfsetfillcolor{bg}
\hfsetbordercolor{red}

\begin{document}

\begin{frame}
  \frametitle{Highlight the minimum cost cell using tikz (Slide 2)}
  \scriptsize
  \begin{tabular}{cccccc}
    \toprule
    Order quantity & Unit price & Annual OC & Annual HC & Annual product cost & Total annual cost\\
    \midrule
    840 & $\$0.85$ & 10 & 30 & 50 & \tikzmarkin<0>{a}\$3686\tikzmarkend{a} \\
    \midrule
    1000 & $\$0.80$ & 20 & 40 & 45 & \tikzmarkin<2->{b}\$3480\tikzmarkend{b} \\
    \bottomrule
  \end{tabular}
\end{frame}

\end{document}

enter image description here

10
  • Thanks. It is appearing easy using hf-tikz. I am relatively new to tikz. If you can please explain. \tikzmarkin<0>{a}\$3686\tikzmarkend{a} Why tikzmarkin is starting at 3686, if the objective is to highlight 3480. Also, what is the use <0> and <2>?
    – mathslove
    Commented Feb 9 at 10:50
  • 1
    @mathslove I added a box to both numbers so they would be aligned in the table. The box for 3686 is shown on the 0th overlay, so never. The box for 3480 is shown on the 2nd overlay, hence the <2> Commented Feb 9 at 10:52
  • I tried \tikzmarkin<+-> so that it appears on the next overlay, but it did not work. Do we need to assign number for overlay?
    – mathslove
    Commented Feb 9 at 10:58
  • 1
    @mathslove Depending on which overlay you are on, it might need \tikzmarkin<+(1)-> Commented Feb 9 at 11:02
  • It worked. Thanks a lot. One more doubt. What is the utility of {a}, {b}? Is it like labeling a box or something else? Also, if I have to start with the basic of using tikz or hf-tikz, is there any resource that I can start with?
    – mathslove
    Commented Feb 9 at 11:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .