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

  • 3
    You can use an escape-character and then \tikzmark from the respective tikz library. – TeXnician Feb 4 '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. – Alex Feb 4 '18 at 15:06
  • Could you please post an MWE that shows what does not work? Please see also this question. – user121799 Feb 4 '18 at 15:34
  • ... and if the code runs over more than one frame, also look at this post. – user121799 Feb 4 '18 at 15:41
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

  • Very nice! But did you try the same thing in the document class beamer? – user121799 Feb 4 '18 at 15:55
  • @marmot I didn't read it the first time. It's the update working for you? – Ignasi Feb 4 '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 – Alex Feb 4 '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}};. – user121799 Feb 4 '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: tex.stackexchange.com/questions/123671/… – Ignasi Feb 4 '18 at 18:12

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.