2

The problem I have is fundamentally the same that was treated here in a very neat way, but for the specific case in which the equations are listed within an align environment. (I recently opened a similar question here but this is an additional problem so I thought it's ok to open a new thread)

I tested the different solutions of @Qrrbrbirlbel but they don't seem to work as they do for equations defined within \[ \].

This is the result:

enter image description here

obtained with the following code

\documentclass{beamer}
\usepackage{pgfplots}
\usepackage{tikz}                       %inline graphics
\usetikzlibrary{calc}

\usepackage[customcolors,markings,shade]{hf-tikz}

\tikzset{nodeStyleGreen/.style={
    draw=green!40!black,
    fill=green!50!lime!30,
    align=left,
    very thick,
    rounded corners
}}

\tikzset{nodeStyleRed/.style={
    draw=red!40!black,
    fill=red!50!lime!30,
    align=left,
    very thick,
    rounded corners
}}

\tikzset{nodeStyleBlue/.style={
    draw=blue!40!black,
    fill=blue!50!lime!30,
    align=left,
    very thick,
    rounded corners
}}

\tikzset{lineStyleRed/.style={
    color=red!40!black,opacity=0.75,line width=2pt,
}}

\tikzset{lineStyleGreen/.style={
    color=green!40!black,opacity=0.75,line width=2pt,
}}

\tikzset{lineStyleBlue/.style={
    color=blue!40!black,opacity=0.75,line width=2pt,
}}

\begin{document}
    \begin{frame}
   %
    \begin{align*}
        \tikzmarkin[nodeStyleRed,mark at=0.5]{firsteq} a &= \int_A^B b \tikzmarkend{firsteq}\\
        %
        \tikz[remember picture,overlay]{
            \node[nodeStyleRed] (firsteq-aa) at ($(firsteq)+(-3.0cm,-1.0cm)$) {
                \begin{minipage}{3cm}
                    My content:\\[-0.5cm]
                    \begin{itemize}
                        \item item 1 of a
                        \item item 2 of a
                    \end{itemize}
                \end{minipage}
                };
                \path [lineStyleRed,use marker id=1] (firsteq-aa.east) edge[out=0,in=185,-stealth] (0,0);
        }
        \tikzmarkin[nodeStyleGreen,mark at=0]{secondeq} b &= c \tikzmarkend{secondeq}\\
        %
        \tikz[remember picture,overlay]{
            \node[nodeStyleGreen] (secondeq-aa) at ($(secondeq)+(5.0,1.0)$) {
                \begin{minipage}{4cm}My other content:\\[-0.5cm]
                    \begin{itemize}
                        \itemsep-0.25em
                        \item item 1
                        \item item 2
                        \item item 3
                    \end{itemize}
                \end{minipage}
            };
            \path [lineStyleGreen,use marker id=1] (secondeq-aa.west) edge[out=180,in=0,-stealth] (0,0);
        }
        %
        \tikzmarkin[nodeStyleBlue,mark at=0.0]{thirdeq} c &= d \tikzmarkend{thirdeq}
        %
        \tikz[remember picture,overlay]{
            \node[nodeStyleBlue] (thirdeq-aa) at ($(thirdeq)+(4.0,-3.0)$) {
                \begin{minipage}{3cm}My final content:\\[-0.5cm]
                    \begin{itemize}
                        \itemsep-0.25em
                        \item item 1
                        \item item 2
                        \item item 3
                    \end{itemize}
                \end{minipage}
            };
            \path [lineStyleBlue,use marker id=1] (thirdeq-aa.west) edge[out=180,in=0,-stealth] (0,0);
        }
    \end{align*}
    %
    \end{frame}
\end{document}
gbernardi
  • 845
  • You could use above left offset and below right offset to expand the box and then add [2pt] of vertical space below a=... so that the expanded box does no to override b=c. – d-cmst Aug 26 '16 at 16:27
  • Sorry, but why are you using overlay etc. rather than just using filled nodes for the lists etc. What am I missing? – cfr Aug 26 '16 at 22:01
  • That is, why not make the whole thing a TikZ picture since everything is highlighted etc., wouldn't that be simpler? – cfr Aug 26 '16 at 22:10
  • The fact that everything is highlighted stems from me being using a dummy example :) I might be highlighting only portions of the equations in the align environment in my presentations/posters. – gbernardi Aug 29 '16 at 08:38

1 Answers1

5

In this kind of case where everything is being highlighted, it really makes work for no reason to write the equations and then add highlighting and annotations and everything else afterwards. It would be simpler to just put the equations in a tikzpicture in the first place.

One way to do this would be to use a matrix of math nodes. If three nodes are used for each equation, they can be aligned using the column <number> styles, as illustrated in the examples in the TikZ manual. Because nodes in matrices automatically get names, the highlighting can then be added around the nodes, together with the annotations afterwards. Using layers, the fill behind the equations can be added using the fit library. Naming these nodes then provides a basis for placing the list of items. I used the positioning library to do this as it seemed simpler than messing around with calc, but you can obviously use that if you prefer. (I've left the library loaded in the example even though I don't actually need it here.)

<code>matrix of math nodes</code> with annotations

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc,matrix,backgrounds,fit,positioning}
\tikzset{%
  nodeStyleGreen/.style={
    draw=green!40!black,
    fill=green!50!lime!30,
    align=left,
    very thick,
    rounded corners
  },
  nodeStyleRed/.style={
    draw=red!40!black,
    fill=red!50!lime!30,
    align=left,
    very thick,
    rounded corners
  },
  nodeStyleBlue/.style={
    draw=blue!40!black,
    fill=blue!50!lime!30,
    align=left,
    very thick,
    rounded corners
  },
  lineStyleRed/.style={
    color=red!40!black,opacity=0.75,line width=2pt,
  },
  lineStyleGreen/.style={
    color=green!40!black,opacity=0.75,line width=2pt,
  },
  lineStyleBlue/.style={
    color=blue!40!black,opacity=0.75,line width=2pt,
  },
}

\begin{document}
\begin{frame}[fragile]
  \begin{tikzpicture}
    \matrix (m) [matrix of math nodes, row sep=2.5pt, column 3/.style={anchor=mid west}, column 2/.style={anchor=mid}, column 1/.style={anchor=mid east}]
    {
      a & = & \int_A^B b\\
      b & = & c\\
      c & = & d\\
    };
    \begin{scope}[on background layer, every node/.style={inner sep=0pt}]
      \node (firsteq) [nodeStyleRed, fit=(m-1-1) (m-1-3)] {};
      \node (secondeq) [nodeStyleGreen, fit=(m-2-1) (m-2-3)] {};
      \node (thirdeq) [nodeStyleBlue, fit=(m-3-1) (m-3-3)] {};
    \end{scope}
    \node [nodeStyleRed, text width=27.5mm, below left=of firsteq.mid west] (firsteq-aa)  {
        My content:
        \begin{itemize}
          \item item 1 of a
          \item item 2 of a
        \end{itemize}
    };
    \path [lineStyleRed] (firsteq-aa.east) edge[out=0,in=185,-stealth] (firsteq);
    \node [nodeStyleGreen, text width=32mm, right=of firsteq.north east] (secondeq-aa) {
      My other content:
        \begin{itemize}
          \itemsep-0.25em
          \item item 1
          \item item 2
          \item item 3
        \end{itemize}
    };
    \path [lineStyleGreen] (secondeq-aa.west) edge[out=180,in=0,-stealth] (secondeq);
    \node [nodeStyleBlue, text width=30mm, below right=of thirdeq.mid east] (thirdeq-aa)  {
      My final content:
        \begin{itemize}
          \itemsep-0.25em
          \item item 1
          \item item 2
          \item item 3
        \end{itemize}
    };
    \path [lineStyleBlue] (thirdeq-aa.west) edge[out=180,in=0,-stealth] (thirdeq);
  \end{tikzpicture}
\end{frame}
\end{document}

Note that you can just set text width rather than messing around with minipages.

cfr
  • 198,882
  • Very nice and understandable solution. Thanks for your help @cfr. I initially thought to bind myself to the use of align just to simplify the transition between my reports and my poster/presentations in beamer, but this seems an easy-to-do adaptation for multiple equations. – gbernardi Aug 29 '16 at 08:36
  • By fiddling around with the code, and re-reading your message, I realized what are some potential problems/drawbacks of this approach. Mainly, highlighting portions is more complicated than using hf-tikz and there are also some problem when the right-most term of the equation is not as big as the other, e.g. if we replace the first eq of my example with a & = & \int_A^B b &+ c, the height of the box is regulated around c and doesn't properly takes the integral into account. – gbernardi Aug 29 '16 at 09:41
  • @gbernardi You need \node (firsteq) [nodeStyleRed, fit=(m-1-1) (m-1-3) (m-1-4)] {}; in that case. – cfr Aug 29 '16 at 13:02
  • Ok, that makes sense. I also noticed that, unlike in an align environment, one has to manually define the alignment style of each column of the matrix; do you know if there is a quick way to define the default alignment style that a standard align would attribute to the equations? (i.e. without having to define the style for each column) – gbernardi Aug 29 '16 at 13:20
  • 1
    @gbernardi I don't think so, but you could define it in a style in your document's preamble and then just type a key like my matrix each time you want the settings applied. So you only need to do it once, really, if you want the same settings. (Or you could put it in a file of standard styles and just load it if you want to use it in lots of different documents.) – cfr Aug 30 '16 at 01:55