This is a poor-cat's version of the nice visible on
style that ships with the beamer-overlay-styles
library. You can assign each element a class, which controls its visibility. So class={1,3}
means that the element shows up on the first and third overlay. If you do a beamer presentation, you can load the beamer-overlay-styles
library, and forget about all this class
stuff and use visible on=<1,3>
instead. However, you may still be interested in the recycle bounding box
style in case that you not only change the visibility but have different elements on different slides, as it happens with \pause
and \ifnum
s.
\documentclass[tikz]{standalone}
\makeatletter
%membership test
\pgfmathdeclarefunction{memberQ}{2}{%
\begingroup%
\edef\pgfutil@tmpb{0}%
\edef\pgfutil@tmpa{#2}%
\expandafter\pgfmath@member@i#1\pgfmath@token@stop
\edef\pgfmathresult{\pgfutil@tmpb}%
\pgfmath@smuggleone\pgfmathresult%
\endgroup}
\def\pgfmath@member@i#1{%
\ifx\pgfmath@token@stop#1%
\else
\edef\pgfutil@tmpc{#1}%
\ifx\pgfutil@tmpc\pgfutil@tmpa\relax%
\gdef\pgfutil@tmpb{1}%
\fi%
\expandafter\pgfmath@member@i
\fi}
\tikzset{recycle bounding box/.style={%
execute at end picture={%
\immediate\write\@mainaux{\xdef\string\figbb@#1{%
(\the\pgf@picminx,\the\pgf@picminy) rectangle (\the\pgf@picmaxx,\the\pgf@picmaxy)}\relax}},
execute at begin picture={%
\ifcsname figbb@#1\endcsname
\edef\figbb{\csname figbb@#1\endcsname}
\path \figbb;
\fi}}}
\makeatother
\usetikzlibrary{
backgrounds,
fit,
matrix,
positioning,
}
\def\Couleur{blue}
\begin{document}
\tikzset{
fleche/.style={->,>=latex,very thick, color=\Couleur!30!white},
mkt/.style={anchor=south ,minimum width=100pt,minimum height=25pt},
logo/.style={anchor=south},
noeud/.style={minimum width=80pt,minimum height=20pt},
central/.style={minimum width=50pt,minimum height=20pt},
bro/.style={font=\tiny,minimum width=40pt, minimum height=10pt},
background/.style={rectangle,rounded corners,inner sep=0.2cm,rounded corners=5mm,opacity=0.7,fill=#1!30},
class/.code={\pgfmathtruncatemacro\itest{memberQ("{#1}",\X)||(\X==5)}%
\ifnum\itest=1
\tikzset{opacity=1}
\else
\tikzset{opacity=0}
\fi
}}
\foreach \X in {1,...,5} {%
\begin{tikzpicture}%[recycle bounding box=A] %if you have size-changing animations
\matrix[matrix of nodes,
row sep = 0.5cm,
column sep = 0.6cm,
every node/.style={rectangle,rounded corners,text centered,draw=\Couleur!50},
row 1/.style={nodes={mkt}},
row 2/.style={nodes={bro}},
row 3/.style={nodes={central}},
row 4/.style={nodes={noeud}},
row 5/.style={nodes={bro}},
ampersand replacement=\&] (orga)
{ |[class={1,3}]| 1-1 \& \& |[class={2,3}]| 1-3 \& \\ %[1cm] %level 1
|[class={1}]| 2-1 \& \& |[class={2}]| 2-3 \& \\ %level 2
\& |[class={5}]| 3-2 \& \& \\ %level 3
|[class={1,4}]| 4-1 \& \& |[class={2,4}]| 4-3 \& \\ [-0.2cm] %level 4
};
%------------------ Flèches -------------------------
% Left
\draw[fleche,class={1}] (orga-1-1) -- (orga-2-1) ;
\draw[fleche,class={1}] (orga-2-1) -- (orga-4-1) ;
% Right
\draw[fleche,class={2}] (orga-1-3) -- (orga-2-3) ;
\draw[fleche,class={2}] (orga-2-3) -- (orga-4-3) ;
% South
\draw[fleche,class={4}] (orga-4-3) -- (orga-4-1) ;
\draw[fleche,class={4}] (orga-4-1.south east) - - (orga-4-3.south west) ;
% From South
%Gauche
\ifnum\X=5
%Up
\draw[fleche] (orga-3-2.north west) - - (orga-1-1.south east);
%Center
\draw[fleche] (orga-2-1.south east) - - (orga-3-2.north west) ;
%Down
\draw[fleche] (orga-4-1.north east) - - (orga-3-2.south west) ;
\draw[fleche] (orga-3-2.south west) - - (orga-4-1.north east);
%Droit
%Up
\draw[fleche] (orga-3-2.north east) - - (orga-1-3.south west);
%Center
\draw[fleche] (orga-2-3.south west) - - (orga-3-2.north east) ;
%Down
\draw[fleche] (orga-4-3.north west) - - (orga-3-2.south east) ;
\draw[fleche] (orga-3-2.south east) - - (orga-4-3.north west);
% \begin{pgfonlayer}{background}
% \node [background={red},
% fit=(orga-1-1) (orga-4-1),
% label=above:{Case 1}] {};
% \node [background={blue},
% fit=(orga-1-3) (orga-4-3),
% label=above:{Case 2}] {};
% \node [background={green},
% fit=(orga-1-1) (orga-1-3),
% label=right:{Case 3}] {};
% \node [background={orange},
% fit=(orga-4-1) (orga-4-3),
% label=right:{Case 4}] {};
% \end{pgfonlayer}
\fi
\end{tikzpicture}}
\end{document}

A slight modification allows you to shrink the "overlays" to their respective size: draw things in the overlay mode and only select the bounding box to include things that you really want.
\documentclass[tikz]{standalone}
\makeatletter
%membership test
\pgfmathdeclarefunction{memberQ}{2}{%
\begingroup%
\edef\pgfutil@tmpb{0}%
\edef\pgfutil@tmpa{#2}%
\expandafter\pgfmath@member@i#1\pgfmath@token@stop
\edef\pgfmathresult{\pgfutil@tmpb}%
\pgfmath@smuggleone\pgfmathresult%
\endgroup}
\def\pgfmath@member@i#1{%
\ifx\pgfmath@token@stop#1%
\else
\edef\pgfutil@tmpc{#1}%
\ifx\pgfutil@tmpc\pgfutil@tmpa\relax%
\gdef\pgfutil@tmpb{1}%
\fi%
\expandafter\pgfmath@member@i
\fi}
\tikzset{recycle bounding box/.style={%
execute at end picture={%
\immediate\write\@mainaux{\xdef\string\figbb@#1{%
(\the\pgf@picminx,\the\pgf@picminy) rectangle (\the\pgf@picmaxx,\the\pgf@picmaxy)}\relax}},
execute at begin picture={%
\ifcsname figbb@#1\endcsname
\edef\figbb{\csname figbb@#1\endcsname}
\path \figbb;
\fi}}}
\tikzset{
reuse path/.code={\pgfsyssoftpath@setcurrentpath{#1}}
}
\makeatother
\usetikzlibrary{
backgrounds,
fit,
matrix,
positioning,
}
\def\Couleur{blue}
\begin{document}
\tikzset{
fleche/.style={->,>=latex,very thick, color=\Couleur!30!white},
mkt/.style={anchor=south ,minimum width=100pt,minimum height=25pt},
logo/.style={anchor=south},
noeud/.style={minimum width=80pt,minimum height=20pt},
central/.style={minimum width=50pt,minimum height=20pt},
bro/.style={font=\tiny,minimum width=40pt, minimum height=10pt},
background/.style={rectangle,rounded corners,inner sep=0.2cm,rounded corners=5mm,opacity=0.7,fill=#1!30},
class/.code={\pgfmathtruncatemacro\itest{memberQ("{#1}",\X)||(\X==5)}%
\ifnum\itest=1
\tikzset{opacity=1,overlay=false}
\else
\tikzset{opacity=0,overlay=true}
\fi
}}
\foreach \X in {1,...,5} {%
\begin{tikzpicture}%[recycle bounding box=A] %if you have size-changing animations
\matrix[matrix of nodes,overlay,
row sep = 0.5cm,
column sep = 0.6cm,
every node/.style={rectangle,rounded corners,text centered,draw=\Couleur!50},
row 1/.style={nodes={mkt}},
row 2/.style={nodes={bro}},
row 3/.style={nodes={central}},
row 4/.style={nodes={noeud}},
row 5/.style={nodes={bro}},
ampersand replacement=\&] (orga)
{ |[class={1,3}]| 1-1 \& |[class={3},noeud,opacity=0]| 2-3 \& |[class={2,3}]| 1-3\\ %[1cm] %level 1
|[class={1}]| 2-1 \& \& |[class={2}]| 2-3\\ %level 2
\& |[class={5}]| 3-2 \& \\ %level 3
|[class={1,4}]| 4-1 \& |[class={4},noeud,opacity=0]| 2-3 \& |[class={2,4}]| 4-3\\[-0.2cm] %level 4
};
%------------------ Flèches -------------------------
% Left
\draw[fleche,class={1}] (orga-1-1) -- (orga-2-1) ;
\draw[fleche,class={1}] (orga-2-1) -- (orga-4-1) ;
% Right
\draw[fleche,class={2}] (orga-1-3) -- (orga-2-3) ;
\draw[fleche,class={2}] (orga-2-3) -- (orga-4-3) ;
% South
\draw[fleche,class={4}] (orga-4-3) -- (orga-4-1) ;
\draw[fleche,class={4}] (orga-4-1.south east) - - (orga-4-3.south west) ;
% From South
%Gauche
\ifnum\X=5
%Up
\draw[fleche] (orga-3-2.north west) - - (orga-1-1.south east);
%Center
\draw[fleche] (orga-2-1.south east) - - (orga-3-2.north west) ;
%Down
\draw[fleche] (orga-4-1.north east) - - (orga-3-2.south west) ;
\draw[fleche] (orga-3-2.south west) - - (orga-4-1.north east);
%Droit
%Up
\draw[fleche] (orga-3-2.north east) - - (orga-1-3.south west);
%Center
\draw[fleche] (orga-2-3.south west) - - (orga-3-2.north east) ;
%Down
\draw[fleche] (orga-4-3.north west) - - (orga-3-2.south east) ;
\draw[fleche] (orga-3-2.south east) - - (orga-4-3.north west);
% \begin{pgfonlayer}{background}
% \node [background={red},
% fit=(orga-1-1) (orga-4-1),
% label=above:{Case 1}] {};
% \node [background={blue},
% fit=(orga-1-3) (orga-4-3),
% label=above:{Case 2}] {};
% \node [background={green},
% fit=(orga-1-1) (orga-1-3),
% label=right:{Case 3}] {};
% \node [background={orange},
% fit=(orga-4-1) (orga-4-3),
% label=right:{Case 4}] {};
% \end{pgfonlayer}
\fi
\begin{scope}[overlay]
\node[fit=(orga-1-1) (orga-4-1)] (F1){};
\node[fit=(orga-1-3) (orga-4-3)] (F2){};
\node[fit=(orga-1-1) (orga-1-3)] (F3){};
\node[fit=(orga-4-1) (orga-4-3)] (F4){};
\end{scope}
\ifnum\X<5
\path[use as bounding box] (F\X.south west) rectangle (F\X.north east);
\else
\path[use as bounding box] (orga.south west) rectangle (orga.north east);
\fi
\end{tikzpicture}}
\end{document}

beamer-overlay-styles
library, same applies to the standalone frame.