\only を使用して表示される複数の tikzpicture を整列させる方法

\only を使用して表示される複数の tikzpicture を整列させる方法

すべて類似しているが、サイズがわずかに異なる一連の tikzpicture があります (突き出ているものがあります)。ただし、それらをすべて tikzpicture の同じポイントに揃えたいと思います。

それらすべてにベースラインを設定すると、その座標点が揃うと考えていましたが、それでもまだ「揺れ」ます。

これが MWE です。各オーバーレイで、(0,0) の開いた円ノードをページ上の同じ場所に配置します。しかし、各 tikzpicture の境界ボックスが中央に配置されるようで、大きな緑のノードがあるためにボックスのサイズが変わります。オプションでbaselineこれが実現できると思っていましたが、そうではありません。

\documentclass{beamer}

\usepackage{tikz}


\begin{document}

\newcommand\grf[1]{
  \begin{tikzpicture}%[baseline={(0,0)}]
    \node[circle,draw] (0) at (0,0) {} ;  % <-- this circle node should not move  
    \node[circle,fill] (1) at (+1,+1) {} ;
    \node[circle,fill] (2) at (+1,-1) {} ;
    \node[circle,fill] (3) at (-1,-1) {} ;
    \node[circle,fill] (4) at (-1,+1) {} ;
    \node[circle,fill,green,inner sep=1em] at (#1) {} ;
  \end{tikzpicture}
}

\begin{frame}
  \only<1>{\grf{1}}%
  \only<2>{\grf{2}}%
  \only<3>{\grf{3}}%
  \only<4>{\grf{4}}%
\end{frame}


\end{document}

答え1

ベースラインを設定しても、境界ボックスは変更される可能性があるため、一般的にジャンプは回避されません。 非常に簡単な修正方法の 1 つは、キーを追加して境界ボックスから余分なノードを除外することですoverlay

\documentclass{beamer}

\usepackage{tikz}
\begin{document}

\newcommand\grf[1]{
  \begin{tikzpicture}%[baseline={(0,0)}]
    \node[circle,draw] (0) at (0,0) {} ;  % <-- this circle node should not move  
    \node[circle,fill] (1) at (+1,+1) {} ;
    \node[circle,fill] (2) at (+1,-1) {} ;
    \node[circle,fill] (3) at (-1,-1) {} ;
    \node[circle,fill] (4) at (-1,+1) {} ;
    \node[circle,fill,green,inner sep=1em,overlay] at (#1) {} ;
  \end{tikzpicture}
}

\begin{frame}
  \only<1>{\grf{1}}%
  \only<2>{\grf{2}}%
  \only<3>{\grf{3}}%
  \only<4>{\grf{4}}%
\end{frame}


\end{document}

ここに画像の説明を入力してください

一般的に、TiZライブラリにはoverlay-beamer-stylesジャンプを回避するためのオプションが多数あります。ここでは

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}

\begin{document}


\begin{frame}
  \begin{tikzpicture}%[baseline={(0,0)}]
    \node[circle,draw] (0) at (0,0) {} ;  % <-- this circle node should not move  
    \node[circle,fill] (1) at (+1,+1) {} ;
    \node[circle,fill] (2) at (+1,-1) {} ;
    \node[circle,fill] (3) at (-1,-1) {} ;
    \node[circle,fill] (4) at (-1,+1) {} ;
    \path foreach \X in {1,...,4}
     {node[circle,fill,green,inner sep=1em,visible on=<\X>] at (\X) {} };
  \end{tikzpicture}
\end{frame}


\end{document}

ここに画像の説明を入力してください

関連情報