
我有一系列 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
設定基線通常並不能避免跳躍,因為邊界框仍然可以改變。一種非常快速的解決方法是透過新增鍵從邊界框中排除額外的節點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}
一般來說,鈦kZ 庫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}