# Tikz figure inside tikz overlay

I would like to create a callout inside my slides. I'm not an expert of tikz, however I find something online.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning,calc,shadows,decorations.pathmorphing,decorations.pathreplacing,tikzmark}
\newcommand{\tikzmarkinside}[1]{\tikz[overlay,remember picture,baseline=-0.5ex] \node (#1) {};}
\begin{document}
\begin{frame}
\begin{itemize}
\item a\tikzmarkinside{first}\pause
\item b\pause
\item c\pause
\end{itemize}

\tikz[remember picture, overlay]\node[align=center, fill=cyan!20,opacity=0.85, text width=4.2cm, rounded corners,
draw,rectangle callout,anchor=pointer,callout absolute pointer=(first.south),
below right= 1 and 1]
at (first) {
\begin{minipage}[t][2cm][t]{4cm}
\begin{tikzpicture}
\draw [fill=orange] (1,1) rectangle (2,2);
\end{tikzpicture}
\end{minipage}
};
\end{frame}
\end{document}


there are two problems here 1) there is a rectangle inside the callout but it has rounded corner, like it has inherited them from the callout shape. I would like to have "square" corners 2) that definition of \tikzmarkinside works but maybe is not so elegant

can you help me?

P.S.: I know that I could use \includegraphics and include a pre-compiled image of my rectangle but I would like to do all at once.

## 1 Answer

You should avoid nesting Tikz pictures. Instead you can draw the callout and the rectangle in the same (overlay) picture. That will also fix the problem with rounded corners.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning,calc,shadows,decorations.pathmorphing,decorations.pathreplacing,tikzmark}
\newcommand{\tikzmarkinside}[1]{\tikz[overlay,remember picture,baseline=-0.5ex] \node (#1) {};}
\begin{document}
\begin{frame}
\begin{itemize}
\item a\tikzmarkinside{first}\pause
\item b\pause
\item c\pause
\end{itemize}

\begin{tikzpicture}[remember picture, overlay]
\node[align=center, fill=cyan!20,opacity=0.85, text width=4.2cm, rounded corners,
draw,rectangle callout,anchor=pointer,callout absolute pointer=(first.south),
below right= 1 and 1,
minimum height=5em]
(TheBubble) at (first) {};
\draw[fill=orange] ($(TheBubble.north west)+(0.2,-0.2)$) rectangle +(1,-1);
\end{tikzpicture}
\end{frame}
\end{document}


EDIT

With a more complicated structure inside the callout I would use a scope to separate it from the rest. The reference point inside the scope is the lower left corner of the callout.

\begin{tikzpicture}[remember picture, overlay]
\node[align=center, fill=cyan!20,opacity=0.85, text width=4.2cm, rounded corners,
draw,rectangle callout,anchor=pointer,callout absolute pointer=(first.south),
below right= 1 and 1,
minimum height=7em]
(TheBubble) at (first) {text inside the callout. It behaves as normal text.
\begin{itemize}
\item Test
\item New test
\end{itemize}
};
%\draw[fill=orange] ($(TheBubble.north west)+(0.2,-0.2)$) rectangle +(1,-1);
\begin{scope}[shift={($(TheBubble.south west) +(0.2,0.2)$)}]
\draw[fill=orange] (0,1) rectangle +(1,1);
\draw[->] (2,0) -- +(0,2) node[left]{$y$};
\draw[->] (2,0) -- +(1.5,0) node[right]{$x$};
\draw[smooth,xshift=2cm] plot coordinates {(0,0)(0.5,1)(1,1.5)(1.5,0.5)};
\end{scope}
\end{tikzpicture}


• Many thanks. The problem is that this was a MWE. In my case inside the callout there is a complex combination of text, formulas and also a tikz figure. I inserted a minipage to contain all. – MaPo Apr 4 '17 at 9:26
• You can do that with scope. See edit. – StefanH Apr 4 '17 at 10:06