将 TikZ 导出为 PDF 并调整大小

将 TikZ 导出为 PDF 并调整大小

我正在尝试创建一个动画,其中创建了两个球,并且它们的半径不断增加。因此,我创建了各种 pdf 并用来\animategraphics创建动画。

但是我对以下代码的输出感到困惑:

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{external} 
\tikzexternalize

\begin{document}
\foreach \r in {0.1,0.5}{
\centering
\begin{tikzpicture}
\pgfmathsetmacro{\rr}{0.05}

\coordinate (1) at (-1.04,0.65);
\coordinate (2) at (2.2,1.18);

\draw[gray,fill=blue] (1) circle (\r);
\draw[gray,fill=blue] (2) circle (\r);
\draw[black,fill=red] (1) circle (\rr);
\draw[black,fill=red] (2) circle (\rr);

\end{tikzpicture}
}
\end{document}

这样会创建两个 pdf。但是如果将第一个图形与第二个图形进行比较,您会注意到中点发生了偏移。因此在动画中中点似乎也在移动。但是我只想炸毁这些点周围的球。

有人知道如何解决我的问题吗?

编辑: 我按照第一条评论(由于某种原因被删除)中的建议,通过在左下角和右上角放置两个透明节点来解决了这个问题。

答案1

使用的框架\animategraphics必须具有相同的物理尺寸。

因此,通过以下方式添加一个公共边界框

\useasboundingbox (...) rectangle (...);
\documentclass[tikz]{standalone}
%\documentclass{scrartcl}
\usepackage{tikz}
%\usetikzlibrary{external} 
%\tikzexternalize

\begin{document}
\foreach \r in {0.1,0.5}{
\begin{tikzpicture}
\pgfmathsetmacro{\rr}{0.05}

\coordinate (1) at (-1.04,0.65);
\coordinate (2) at (2.2,1.18);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\useasboundingbox ([shift={(-0.51,-0.51)}] 1) rectangle ([shift={(0.51,0.51)}] 2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\draw[gray,fill=blue] (1) circle (\r);
\draw[gray,fill=blue] (2) circle (\r);
\draw[black,fill=red] (1) circle (\rr);
\draw[black,fill=red] (2) circle (\rr);

\end{tikzpicture}
}
\end{document}

使用环境的示例animateinline

\documentclass[a6paper]{scrartcl}
\usepackage{tikz}
\usepackage{animate}

\begin{document}

\begin{animateinline}[loop,autoplay]{12}
  \multiframe{41}{r=0.1+0.01}{
    \begin{tikzpicture}
    \pgfmathsetmacro{\rr}{0.05}

    \coordinate (1) at (-1.04,0.65);
    \coordinate (2) at (2.2,1.18);
    \useasboundingbox ([shift={(-0.51,-0.51)}] 1) rectangle ([shift={(0.51,0.51)}] 2);

    \draw[gray,fill=blue] (1) circle (\r);
    \draw[gray,fill=blue] (2) circle (\r);
    \draw[black,fill=red] (1) circle (\rr);
    \draw[black,fill=red] (2) circle (\rr);

    \end{tikzpicture}
  }
\end{animateinline}
\end{document}

相关内容