当我在每张幻灯片中使用相同的 tikzmark 标签时,我会遇到问题

当我在每张幻灯片中使用相同的 tikzmark 标签时,我会遇到问题

为了使我的 tikzmark 正确显示,我不需要为每个 tikzmark 使用不同的名称。 跟踪名称很麻烦,有办法解决这个问题吗? 在下面的代码中,如果我将 tikzmark{B1} 替换为 tikzmark{G1},我的代码就可以正常工作。 \documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{calc,tikzmark,arrows,shapes,backgrounds,decorations.pathreplacing}

\tikzset{
  every picture/.append style={remember picture},
  na/.style={baseline=-.5ex},
  arrow/.style={-stealth}
}  

\newcommand\MyFont[1]{%
  {\scriptsize\bfseries\texttt{\textcolor{blue}{#1}}}%
}

\newcommand{\mytikzmark}[1]{\tikz[overlay,remember picture] \node[baseline] (#1) {};}


\begin{document}

\begin{frame}{Anonymous Functions}
\begin{itemize}
\item You do not have to make a separate function file

\MyFont{>> x=fzero(@myfun,1)}

  \begin{itemize}\item What if myfun is really simple?\end{itemize}
  \item Instead, you can make an anonymous function

  \MyFont{
    >> x=fzero(@(\tikzmark{B1}x)
  (cos(exp(x))+x\textasciicircum 2-1), 1 )}
    \vspace{0.8cm}

  \MyFont{>> x=fminbnd(@(x) (cos(exp(x))+x\textasciicircum2-1),-1,2);}
  \end{itemize}

\begin{tikzpicture}[remember picture,overlay]
\draw[arrow] 
  ( $ (pic cs:B1) + (-10pt,-0.3cm) $ ) node[below,font=\scriptsize] {input} -- 
  ( $ (pic cs:B1) + (0.4ex,-2pt) $ );

\end{tikzpicture}
\end{frame}\begin{frame}{Numerical Differentiation}

\begin{itemize}
\item MATLAB can \lq differentiate' numerically
\newline
{\scriptsize{\fontseries{b}\texttt{
\textcolor{blue}{>> fx=0:0.01:2*pi;\\
>> y=sin(x);\tikzmark{B1}\\
>> dydx=diff(y)./diff(x);\\}}}}
\begin{itemize}\item diff computes the first difference\end{itemize}
\item Can also operate on matrices
\newline
{\scriptsize{\fontseries{b}\texttt{
\textcolor{blue}{>> fmat=[1 3 5;4 8 6];\\
>> dm=diff(mat,1,2)}}}}
\begin{itemize}\item first difference of mat along the 2nd dimension, dm=[2 2;4 -2]
\item see {\textbf{\textcolor{orange}{help}}} for more details
\item The opposite of {\scriptsize{\fontseries{b}\texttt{
\textcolor{blue}{diff}}}} is the cumulative sum {\scriptsize{\fontseries{b}\texttt{
\textcolor{blue}{cumsum}}}} \end{itemize}
\item 2D gradient
\newline
{\scriptsize{\fontseries{b}\texttt{
\textcolor{blue}{>>  [dx,dy]=gradient(mat);}}}}
\end{itemize}

\begin{tikzpicture}[remember picture,overlay]
\node  at ( $ (pic cs:B1) + (7cm,-0.6cm) $ )  {\includegraphics[width=4.5cm]{pic2.jpg}};
 \path[->,blue,thick] ($(pic cs:B1)+ (0.4ex,1pt) $) edge ($(pic cs:B1)+ (5.5cm,0cm) $);

\end{tikzpicture}
\end{frame}

\end{document}

答案1

就我所知,此操作运行无误,看起来不错。我不得不用示例图像代替 pic2.jpg

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc,tikzmark,arrows,shapes,backgrounds,decorations.pathreplacing}

\tikzset{
  every picture/.append style={remember picture},
  na/.style={baseline=-.5ex},
  arrow/.style={-stealth}
}  

\newcommand\MyFont[1]{%
  {\scriptsize\bfseries\texttt{\textcolor{blue}{#1}}}%
}

\newcommand{\mytikzmark}[1]{\tikz[overlay,remember picture] \node[baseline] (#1) {};}


\begin{document}

\begin{frame}{Anonymous Functions}
\begin{itemize}
\item You do not have to make a separate function file

\MyFont{>> x=fzero(@myfun,1)}

  \begin{itemize}\item What if myfun is really simple?\end{itemize}
  \item Instead, you can make an anonymous function

  \MyFont{
    >> x=fzero(@(\tikzmark{B\thepage}x)
  (cos(exp(x))+x\textasciicircum 2-1), 1 )}
    \vspace{0.8cm}

  \MyFont{>> x=fminbnd(@(x) (cos(exp(x))+x\textasciicircum2-1),-1,2);}
  \end{itemize}

\begin{tikzpicture}[remember picture,overlay]
\draw[arrow] 
  ( $ (pic cs:{B\thepage}) + (-10pt,-0.3cm) $ ) node[below,font=\scriptsize] {input} -- 
  ( $ (pic cs:{B\thepage}) + (0.4ex,-2pt) $ );

\end{tikzpicture}
\end{frame}\begin{frame}{Numerical Differentiation}

\begin{itemize}
\item MATLAB can \lq differentiate' numerically
\newline
{\scriptsize{\fontseries{b}\texttt{
\textcolor{blue}{>> fx=0:0.01:2*pi;\\
>> y=sin(x);\tikzmark{B\thepage}\\
>> dydx=diff(y)./diff(x);\\}}}}
\begin{itemize}\item diff computes the first difference\end{itemize}
\item Can also operate on matrices
\newline
{\scriptsize{\fontseries{b}\texttt{
\textcolor{blue}{>> fmat=[1 3 5;4 8 6];\\
>> dm=diff(mat,1,2)}}}}
\begin{itemize}\item first difference of mat along the 2nd dimension, dm=[2 2;4 -2]
\item see {\textbf{\textcolor{orange}{help}}} for more details
\item The opposite of {\scriptsize{\fontseries{b}\texttt{
\textcolor{blue}{diff}}}} is the cumulative sum {\scriptsize{\fontseries{b}\texttt{
\textcolor{blue}{cumsum}}}} \end{itemize}
\item 2D gradient
\newline
{\scriptsize{\fontseries{b}\texttt{
\textcolor{blue}{>>  [dx,dy]=gradient(mat);}}}}
\end{itemize}

\begin{tikzpicture}[remember picture,overlay]
\node  at ( $ (pic cs:{B\thepage}) + (7cm,-0.6cm) $ )  {\includegraphics[width=4.5cm]{example-image}};
 \path[->,blue,thick] ($(pic cs:{B\thepage})+ (0.4ex,1pt) $) edge ($(pic cs:{B\thepage})+ (5.5cm,0cm) $);

\end{tikzpicture}
\end{frame}

\end{document}

两页

相关内容