当我用 tikz 画箭头时阻止桌子移动

当我用 tikz 画箭头时阻止桌子移动

我在每张幻灯片中显示一个单元格,每行完全显示后,我使用 tikz 在该行上绘制一个箭头。

当单元格出现时,表格固定在幻灯片的同一位置,但是,当显示箭头时,表格会移动(通常在 y 轴向上移动)。

你知道我该怎么做才能让桌子始终保持固定吗?

例如,考虑下面的代码,它产生此 PDF

\documentclass{beamer}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}

\begin{frame}

\begin{table}
    \centering
    \begin{tabular}{|c|c|c|}
        \hline
        & $u = 1$ & $u = 2$ 
        \\
        \hline
        $v = 1$ & \onslide<2-7>{ A } & \onslide<3-7>{ B }
        \\
        \hline
        $v = 2$ & \onslide<5-7>{ C } & \onslide<6-7>{ D } \\
        \hline
    \end{tabular}
\end{table}

%% draw an arrow over the first row of the table
\only<4>{
\begin{tikzpicture}[overlay,remember picture]
    \draw [->,thick,color=red] (5, 1.25) to (8, 1.25);
\end{tikzpicture}
}
%% draw an arrow over the second row of the table
\only<7>{
\begin{tikzpicture}[overlay,remember picture]
    \draw [->,thick,color=red] (5, 0.75) to (8, 0.75);
\end{tikzpicture}
}

\end{frame}
\end{document}

答案1

编辑文件方法一:

\documentclass{beamer}
\usepackage[english]{babel}
\usepackage{tikz}

\newcommand{\tikzmark}[2]{%
\tikz[overlay,remember picture,baseline] \node[anchor=base] (#1) {$#2$};}


\begin{document}

\begin{frame}

\begin{table}
    \centering
    \begin{tabular}{|c|c|c|}
        \hline
        & $u = 1$ & $u = 2$ 
        \\
        \hline
        $v = 1$ & \tikzmark{a}{\onslide<2-7>{ A }} & \tikzmark{b}{\onslide<3-7>{ B }}
        \\
        \hline
        $v = 2$ & \tikzmark{c}{\onslide<5-7>{ C }} & \tikzmark{d}{\onslide<6-7>{ D }} \\
        \hline
    \end{tabular}
\end{table}
%
\begin{tikzpicture}[overlay,remember picture]
\only<4>{ \draw [->,thick,color=red] ([xshift=-1.5mm]a.west) -- ([xshift=10mm]b.east);}
 \only<7>{ \draw [->,thick,color=red] ([xshift=-1.5mm]c.west) -- ([xshift=10mm]d.east);}
\end{tikzpicture}

\end{frame}
\end{document}

编辑文件方法2:

\documentclass{beamer}
\usepackage[english]{babel}
\usepackage{tikz}

\usetikzlibrary{tikzmark}

\begin{document}

\begin{frame}

\begin{table}
    \centering
    \begin{tabular}{|c|c|c|}
        \hline
        & $u = 1$ & $u = 2$ 
        \\
        \hline
        $v = 1$ & \tikzmark{a}\onslide<2-7>{ A } & \onslide<3-7>{ B }\tikzmark{b}
        \\
        \hline
        $v = 2$ & \tikzmark{c}\onslide<5-7>{ C } & \onslide<6-7>{ D }\tikzmark{d} \\
        \hline
    \end{tabular}
\end{table}
%
\begin{tikzpicture}[overlay,remember picture]
\only<4>{ \draw [->,thick,color=red] ([xshift=-1.5mm,yshift=1.3mm]pic cs:a) -- ([xshift=10mm,yshift=1.3mm]pic cs:b);}
 \only<7>{ \draw [->,thick,color=red] ([xshift=-1.5mm,yshift=1.3mm]pic cs:c) -- ([xshift=10mm,yshift=1.3mm]pic cs:d);}
\end{tikzpicture}

\end{frame}
\end{document}

输出TL2020: 在此处输入图片描述

相关内容