I am trying to adapt the second solution of "Label variables of the equation using Tikz without using itemize " to my equation, P_t= P_T G_T G_t H_f.

The code is the following:

\documentclass{beamer}
\usetheme[progressbar=frametitle]{metropolis}
\setbeamertemplate{frame numbering}[fraction]
\useoutertheme{metropolis}
\useinnertheme{metropolis}
\usefonttheme{metropolis}
\usecolortheme{spruce}
\setbeamercolor{background canvas}{bg=white}
\definecolor{mygreen}{rgb}{.125,.5,.25}
\usecolortheme[named=mygreen]{structure}
\setbeamercovered{transparent=15}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{>=stealth}
\newcommand{\tikzmark}[3][]{\tikz[overlay,remember picture,baseline] \node [anchor=base,#1](#2) {#3};}
\begin{document}
\begin{frame}[t]{Channel model}
        \begin{itemize}
            \item<1-> The power coupled into the IC, $P_t$ is
        \end{itemize}
            \begin{equation*}
                P_t = \tikzmark{identity}{P_T} \tikzmark[red]{G}{G_T}\, 
                \tikzmark[blue]{L}{G_t} \tikzmark[purple]{C}{H_f}
            \end{equation*}

            \begin{tikzpicture}[overlay, remember picture,node distance =1.5cm]
                \node (identitydescr) [below left=of identity ]{transmitted power of the sender};
                \draw[,->,thick] (identitydescr) to [in=-90,out=90] (identity);
                \node[red] (Gdescr) [below =of G]{gain of the transmitter antenna};
                \draw[red,->,thick] (Gdescr) to [in=-90,out=90] (G);
                \node[blue,xshift=1cm] (Ldescr) [above right =of L]{gain of the box antenna};
                \draw[blue,->,thick] (Ldescr) to [in=45,out=-90] (L.north);
                \node[purple] (Cdescr) [below right =of C]{attenuation of the transmitted power};
                \draw[purple,->,thick] (Cdescr) to [in=-90,out=90] (C.south);
            \end{tikzpicture}
    \end{frame}
\end{document}

But it does not work as the linked solution above does. There seem to be several problems in the code, like tikzmark does not work with math like G_T. Besides, the labels can not break in several lines. I have tried \\but it does not work. I would also like to be able to place the tikzpicture in some part below the text. Now it overlies the first text line, or if I put the tikzpicture into the itemize environment, the arrows and labels appear displaced.

I would like to know how to control the bend and position of the arrows specified with the in and out angles.

Regards

up vote 6 down vote accepted

There are a couple of problems:

  • If you want to use things like P_T in the \tikzmark, you need math mode

  • Your previous definition of \tikzmark contained overlay as option, this hides the width of the content, thus all your letters were superimposed.

  • To get line breaks in your descriptions, you can use pass the text width option to the node.

  • if you load the metropolis theme, there is no need to load its outer, inner and font themes a second time.


And please don't listen to @marmot and accept his answer :)


\documentclass{beamer}

\usetheme[progressbar=frametitle]{metropolis}
\setbeamertemplate{frame numbering}[fraction]
\usecolortheme{spruce}
\setbeamercolor{background canvas}{bg=white}
\definecolor{mygreen}{rgb}{.125,.5,.25}
\usecolortheme[named=mygreen]{structure}
\setbeamercovered{transparent=15}
\usepackage{pgfplots}


\usepackage{amsmath} % loaded automatically by beamer
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{>=stealth}

\newcommand{\tikzmark}[3][]{\tikz[remember picture,baseline] \node [anchor=base,#1](#2) {$#3$};}

\begin{document}
\begin{frame}[t]{Channel model}
    \begin{itemize}
        \item<1-> The power coupled into the IC, $P_t$ is
    \end{itemize}
        \begin{equation*}
            P_t = \tikzmark{identity}{P_T}\tikzmark[red]{G}{G_T}
            \tikzmark[blue]{L}{G_t}\tikzmark[purple]{C}{H_f}
        \end{equation*}
       \begin{tikzpicture}[overlay, remember picture,node distance =1.5cm]
            \node[,text width=2cm] (identitydescr) [below left=of identity ]{transmitted power of the sender};
            \draw[,->,thick] (identitydescr) to [in=-90,out=90] (identity);
            \node[red,text width=2cm] (Gdescr) [below =of G]{gain of the transmitter antenna};
            \draw[red,->,thick] (Gdescr) to [in=-90,out=90] (G);
            \node[blue,xshift=1cm,text width=2cm] (Ldescr) [above right =of L]{gain of the box antenna};
            \draw[blue,->,thick] (Ldescr) to [in=45,out=-90] (L.north);
            \node[purple,text width=2cm] (Cdescr) [below right =of C]{attenuation of the transmitted power};
            \draw[purple,->,thick] (Cdescr) to [in=-90,out=90] (C.south);
        \end{tikzpicture}
\end{frame}
\end{document}

enter image description here

  • Thank you for the answer. I did not know the metropolis theme include those options. – user1993416 Aug 17 at 19:23
  • @user1993416 You're welcome! As a rule of thumb: if a theme is divided in color/font/inner/outer theme, the main theme file usually loads all of them. – samcarter Aug 17 at 19:30

Your code compiles beautifully if you use the tricks of this answer. But you should really accept samcarter's nice answer. There it is explained why you got the error. Torbjørn's answer solves that problem by using \ifmmode to check whether the node is in a math environment. I also appended a text width to the nodes of the picture, as suggested by samcarter, and shortened the arrows a bit.

\documentclass{beamer}
\usetheme[progressbar=frametitle]{metropolis}
\setbeamertemplate{frame numbering}[fraction]
\useoutertheme{metropolis}
\useinnertheme{metropolis}
\usefonttheme{metropolis}
\usecolortheme{spruce}
\setbeamercolor{background canvas}{bg=white}
\definecolor{mygreen}{rgb}{.125,.5,.25}
\usecolortheme[named=mygreen]{structure}
\setbeamercovered{transparent=15}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{>=stealth}
% https://tex.stackexchange.com/a/402466/121799
\newcommand{\tikzmark}[3][]{
\ifmmode
\tikz[remember picture,baseline=(#2.base)] \node [inner sep=0pt,#1](#2) {$#3$};
\else
\tikz[remember picture,baseline=(#2.base)] \node [inner sep=0pt,#1](#2) {#3};
\fi
}
\begin{document}
\begin{frame}[t]{Channel model}
        \begin{itemize}
            \item<1-> The power coupled into the IC, $P_t$ is
        \end{itemize}
            \begin{equation*}
                P_t = \tikzmark{identity}{P_T} \tikzmark[red]{G}{G_T}\, 
                \tikzmark[blue]{L}{G_t} \tikzmark[purple]{C}{H_f}
            \end{equation*}

            \begin{tikzpicture}[overlay, remember picture,node distance =1.5cm,
            every node/.append style={text width=3cm,align=center},
            shorten >=1pt]
                \node (identitydescr) [below left=of identity ]{transmitted power of the sender};
                \draw[,->,thick] (identitydescr) to [in=-90,out=90] (identity);
                \node[red] (Gdescr) [below =of G]{gain of the transmitter antenna};
                \draw[red,->,thick] (Gdescr) to [in=-90,out=90] (G);
                \node[blue,xshift=1cm,yshift=-0.6cm] (Ldescr) [above right =of L]{gain of the box antenna};
                \draw[blue,->,thick] (Ldescr) to [in=45,out=-90] (L.north);
                \node[purple] (Cdescr) [below right =of C]{attenuation of the transmitted power};
                \draw[purple,->,thick] (Cdescr) to [in=-90,out=90] (C.south);
            \end{tikzpicture}
    \end{frame}
\end{document}

enter image description here

You can center the equation brute force using \vfill. in and out are just the angles of the ingoing or outgoing path, something like an impact angle and the analog for the outgoing path. By default, TikZ starts the node at a position that it finds appropriate. You could overrule this e.g. by

\draw[->,thick] (identitydescr.north east) to [in=-90,out=90] (identity);

but I do not like the result. If you change the impact and outgoing angles

\draw[->,thick] (identitydescr) to [in=-45,out=45] (identity);

you get

enter image description here

Another parameter to play with is looseness, which gets varied in the animation

\documentclass{beamer}
\usetheme[progressbar=frametitle]{metropolis}
\setbeamertemplate{frame numbering}[fraction]
\useoutertheme{metropolis}
\useinnertheme{metropolis}
\usefonttheme{metropolis}
\usecolortheme{spruce}
\setbeamercolor{background canvas}{bg=white}
\definecolor{mygreen}{rgb}{.125,.5,.25}
\usecolortheme[named=mygreen]{structure}
\setbeamercovered{transparent=15}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{>=stealth}
% https://tex.stackexchange.com/a/402466/121799
\newcommand{\tikzmark}[3][]{
\ifmmode
\tikz[remember picture,baseline=(#2.base)] \node [inner sep=0pt,#1](#2) {$#3$};
\else
\tikz[remember picture,baseline=(#2.base)] \node [inner sep=0pt,#1](#2) {#3};
\fi
}
\begin{document}
\foreach \X in {0.5,0.6,...,1.2,1.4,...,2}
{\begin{frame}[t]{Channel model}
        \begin{itemize}
            \item<1-> The power coupled into the IC, $P_t$ is
        \end{itemize}
        \vfill
            \begin{equation*}
                P_t = \tikzmark{identity}{P_T} \tikzmark[red]{G}{G_T}\, 
                \tikzmark[blue]{L}{G_t} \tikzmark[purple]{C}{H_f}
            \end{equation*}
\vfill
            \begin{tikzpicture}[overlay, remember picture,node distance =1.5cm,
            every node/.append style={text width=3cm,align=center},
            shorten >=1pt,looseness=\X]
                \node (identitydescr) [below left=of identity ]{transmitted power of the sender};
                \draw[,->,thick] (identitydescr) to [in=-90,out=90] (identity);
                \node[red] (Gdescr) [below =of G]{gain of the transmitter antenna};
                \draw[red,->,thick] (Gdescr) to [in=-90,out=90] (G);
                \node[blue,xshift=1cm] (Ldescr) [above right =of L]{gain of the box antenna};
                \draw[blue,->,thick] (Ldescr) to [in=45,out=-90] (L.north);
                \node[purple] (Cdescr) [below right =of C]{attenuation of the transmitted power};
                \draw[purple,->,thick] (Cdescr) to [in=-90,out=90] (C.south);
            \end{tikzpicture}
    \end{frame}}
\end{document}

enter image description here

  • 1
    Seems we have the same taste for questions to answer at the moment :) – samcarter Aug 17 at 18:53
  • @samcarter Looks like it... ;-) – marmot Aug 17 at 18:55
  • 1
    Let's meet again at the next question :) – samcarter Aug 17 at 18:55
  • @marmot I am using this answer and it works fine. It seems takes the text lines of the labels and break it automatically. I think the result is beautiful. I would like to ask you if it is possible to move the whole tikzpicture to the center of the slide, and also if you could explain about the arrows form (the in out angles) and the length of the arrow. Thanks. – user1993416 Aug 17 at 19:30
  • 1
    @marmot I have already accepted samcarter's answer :-)). – user1993416 Aug 17 at 19:37

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.