如何解决在幻灯片中放置带图片的节点时出错的问题

如何解决在幻灯片中放置带图片的节点时出错的问题

我想问一下这个beamer代码编译错误该如何解决:

\documentclass{beamer}
\usepackage{multicol}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{positioning}
\graphicspath{{_figs/}}
\usepackage{graphicx}
\usetheme[progressbar=frametitle]{metropolis}
\setbeamertemplate{frame numbering}[fraction]
\useoutertheme{metropolis}
\useinnertheme{metropolis}
\usefonttheme{metropolis}
\setbeamercolor{background canvas}{bg=white}

\setbeamercovered{transparent=10}

\title[GdR (U.1.1.)]{Introduction to GdR}
\author[Manhatan]{John Doe\\
\vspace{0.5cm}
Course of Statistics\\
}
\date{Octubre 2021} 

\begin{document}
    \metroset{block=fill}
    
    \begin{frame}[t]{}
        \titlepage
    \end{frame}
    %--- Next Frame ---%
    
    \section{Definitión} % (fold)
    \label{sec:definition}
    \begin{frame}[t]{Analogy}
        \begin{tikzpicture}
            \visible<1-2>{\node at
                [xshift=5cm, yshift=0cm](current page.center)
                {\includegraphics[width=0.3\textwidth,]{VS.jpg}}; }
        
        \end{tikzpicture}
    \end{frame}
    %--- Next Frame ---%
    % section definition (end)
\end{document}

文件VS.jpg是这样的:

在此处输入图片描述

编译时的错误是:

Package tikz Error: Cannot parse this coordinate.

答案1

这里有几个问题:

  1. 相对于节点移位的语法是:
\node at ([xshift=5cm, yshift=0cm]current page.center)...

所以你必须包括转移的选项里面节点名称括号。

  1. 如果您想访问在页面中创建的节点,(current page)您应该将选项添加remember picture, overlay到您的tikzpicture
  2. 无关,但有一个警告Token not allowed in a PDF string...。这是因为您在作者姓名中包含了 LaTeX:\\\vspace... 要避免此警告,您可以使用宏\texorpdfstring

更正后的代码可能是:

\documentclass{beamer}
\usepackage{multicol}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{positioning}
\graphicspath{{_figs/}}
\usepackage{graphicx}
\usetheme[progressbar=frametitle]{metropolis}
\setbeamertemplate{frame numbering}[fraction]
\useoutertheme{metropolis}
\useinnertheme{metropolis}
\usefonttheme{metropolis}
\setbeamercolor{background canvas}{bg=white}

\setbeamercovered{transparent=10}

\title[GdR (U.1.1.)]{Introduction to GdR}
\author[Manhatan]{John Doe\\\texorpdfstring{\\[0.5cm]}{--} % LaTeX is not allowd in the pdf author tag
Course of Statistics
}
\date{Octubre 2021} 

\begin{document}
    \metroset{block=fill}
    
    \begin{frame}[t]{}
      \titlepage
    \end{frame}
    %--- Next Frame ---%
    
    \section{Definition} % (fold)
    \label{sec:definition}
    \begin{frame}[t]{Analogy}
        \begin{tikzpicture}[remember picture,overlay]
            \visible<1-2>{\node at
                ([xshift=2cm, yshift=0cm]current page.center)
                {\includegraphics[width=0.3\textwidth,]{example-image}}; }
            % added for showing the change
            \visible<3>{\node at
                ([xshift=-2cm, yshift=0cm]current page.center)
                {\includegraphics[width=0.3\textwidth,]{example-image}}; }
        \end{tikzpicture}
    \end{frame}
    %--- Next Frame ---%
    % section definition (end)
\end{document}

相关内容