pgfgantt beamer 中的动画甘特图

pgfgantt beamer 中的动画甘特图

我正在尝试应用类似这里的动画Beamer 中的 Tikz 动画人物到使用 pgfgantt 的甘特图:我试图让甘特图在单击后逐渐出现。如果我手动将键中的fill opacityopacity键更改为 0 ganttbar,我会看到它们出现并消失,所以我知道可以工作。但我不确定如何编辑我的代码以将invisiblevisible样式添加到我的栏中并将其与<2->事件联系起来,就像 tikz 示例中那样:

\tikzset{
  invisible/.style={opacity=0},
  visible on/.style={alt={#1{}{invisible}}},
  alt/.code args={<#1>#2#3}{%
    \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
  },
}

我的工作示例,其中我可以手动更改条的不透明度:


\documentclass{article}
\usepackage{pgfgantt}
\begin{document}
\definecolor{color1}{HTML}{878787}
\definecolor{color3}{HTML}{ff0000}
  \begin{figure}
          \centering
          \begin{tikzpicture}
            \begin{ganttchart}[
                expand chart=\textwidth,
                hgrid,
                vgrid
            ]{1}{15}
                \gantttitlelist{1,...,15}{1} \\
                \ganttbar[bar/.append style={fill=color1}, inline, bar label font=\tiny\bfseries]{}{2}{3}
                \ganttbar[bar/.append style={fill=color3, pattern=north west lines, pattern color=color3, fill opacity=1, opacity=1}, inline, bar label font=\tiny\bfseries]{ }{5}{8}
                \node (a) [anchor=north] at (current bounding box.south east){};
                \node (m) [fill=color1,draw, label=left:{Check}, minimum width=1.5cm, minimum height=0.5cm, anchor=north] at ([yshift=-12pt]a.south east){};
                \node[fill=color3,draw, label=left:{Mission assignment}, minimum width=1.5cm, minimum height=0.5cm, pattern=north west lines, pattern color=color3] at ([yshift=-12pt]m.south){};
            \end{ganttchart}

          \end{tikzpicture}
  \end{figure}
\end{document}

答案1

显然,一种简单的方法是为每个条形图添加\onslide,然后使用 beamer 运行时“它就可以正常工作”。我应该早点试一下……

\documentclass[leqno,mathserif]{beamer}  
\usepackage{graphics,bm}
\usetheme{Luebeck} 
\usepackage{pgfgantt}
\definecolor{color1}{HTML}{878787}
\definecolor{color3}{HTML}{ff0000}
\begin{document}
\begin{frame}
  \begin{figure}
          \centering
          \begin{tikzpicture}
            \begin{ganttchart}[
                expand chart=\textwidth,
                hgrid,
                vgrid
            ]{1}{15}
                \gantttitlelist{1,...,15}{1} \\
                \onslide<2->{
                  \ganttbar[bar/.append style={fill=color1}, inline, bar label font=\tiny\bfseries]{}{2}{3}
                }
                \onslide<3->{
                  \ganttbar[bar/.append style={fill=color3, pattern=north west lines, pattern color=color3, fill opacity=1, opacity=1}, inline, bar label font=\tiny\bfseries]{ }{5}{8}
                }
                \node (a) [anchor=north] at (current bounding box.south east){};
                \node (m) [fill=color1,draw, label=left:{Check}, minimum width=1.5cm, minimum height=0.5cm, anchor=north] at ([yshift=-12pt]a.south east){};
                \node[fill=color3,draw, label=left:{Mission assignment}, minimum width=1.5cm, minimum height=0.5cm, pattern=north west lines, pattern color=color3] at ([yshift=-12pt]m.south){};
            \end{ganttchart}
          \end{tikzpicture}
  \end{figure}
\end{frame}
\end{document}

相关内容