0

I make a presentation 'beamer' with several slides of code using 'Code Listings', I would like to put cloud messages in some reserved words of the code for its explanation.

I have searched and I have not seen any questions or examples that make the messages about 'Code Listings' in the place that I indicate.

Similar to this: enter image description here

This is possible?

regards

affernan
  • 189
  • 3
    You can use an escape-character and then \tikzmark from the respective tikz library. – TeXnician Feb 04 '18 at 14:49
  • Hello @TeXnician, thanks for your answer, I tried your possible solution, but doesn't work because when I enter the block [ ... ] inside \begin{lstlisting} ... end {lstlisting}, it does not perform the arrows, but presents the script as it is in LaTeX. – affernan Feb 04 '18 at 15:06
  • Could you please post an MWE that shows what does not work? Please see also this question. –  Feb 04 '18 at 15:34
  • ... and if the code runs over more than one frame, also look at this post. –  Feb 04 '18 at 15:41

1 Answers1

7

An example:

enter image description here

\documentclass{article}
\usepackage{listings}
\usepackage{tikz}
\usetikzlibrary{tikzmark, shapes.callouts}

\begin{document}
\begin{lstlisting}[mathescape]
this is the first$\tikzmark{aux}$ line
This is the second line
\end{lstlisting}

\begin{tikzpicture}[overlay, remember picture]
\node[rectangle callout, rounded corners, 
      callout absolute pointer={(pic cs:aux)}, 
      draw] at ([yshift=1cm]pic cs:aux){Note};
\end{tikzpicture}
\end{document}

Update: For beamer which I skipped reading the question.

\documentclass{beamer}
\usepackage{listings}
\usepackage{tikz}
\usetikzlibrary{tikzmark, shapes.callouts}

\begin{document}

\begin{frame}[fragile]{First frame}
\begin{lstlisting}[mathescape]
this is the first$\tikzmark{aux}$ line
This is the second line
\end{lstlisting}

\begin{tikzpicture}[overlay, remember picture]

\node[rectangle callout, rounded corners, callout absolute pointer={(pic cs:aux)}, draw] at ([yshift=1cm]pic cs:aux){Note};
\end{tikzpicture}
\end{frame}
\end{document}

enter image description here

Ignasi
  • 136,588
  • Very nice! But did you try the same thing in the document class beamer? –  Feb 04 '18 at 15:55
  • @marmot I didn't read it the first time. It's the update working for you? – Ignasi Feb 04 '18 at 16:00
  • Thanks @Ignasi, it work, got it. How put several lines inner rectangle??, I try this: ... pic cs:aux){ Definition proposed $\linebreak$ second part}; , but doesn't work – affernan Feb 04 '18 at 17:38
  • 1
    @Alex: You can always put a table in the node, e.g. \node[rectangle callout, rounded corners, callout absolute pointer={(pic cs:aux)}, draw] at ([yshift=1cm]pic cs:aux){\begin{tabular}{c}this is\\ some lengthy\\ explanation\end{tabular}};. –  Feb 04 '18 at 17:51
  • 1
    @Alex: You have to define a certain text width in node options. The text will adjust to this width and you can also introduce line breaks with \\. See: https://tex.stackexchange.com/questions/123671/manual-automatic-line-breaks-and-text-alignment-in-tikz-nodes – Ignasi Feb 04 '18 at 18:12