有问题
在(一堂课)结束时,这是我想要显示的完整图表。
但在课堂上,我会一步步地只有节点和箭头在“案例编号”区域(就像最后的顿悟一样,不同的区块都是连接在一起的)。
我的问题
以案例 1 为例。首先,我只想显示严格位于红色区域中的节点和箭头(不显示指向其他节点的箭头,也不显示区域外的其他节点)。但如果我执行简单的操作\ifBlock1true
,我当然会遇到来自 3-2 和 4-3 的箭头带来的麻烦。
对于每一种情况,\newif
我都会遇到箭头问题,最终需要在完整的图表中显示出来。
编辑1
正如您所见,@Schrodingerscat 的精彩答案重新创建了与visible on
outside相同的内容beamer
。
正如评论中所讨论的那样,将这些图形逐块插入或中作为单个图形article
将book
留下空白,节点的白色阴影尚未显示。(解决方案 1)。我愿意拥有可以用调用的单独块。然后将每个块放在或\def\Block{i} \input{Maingraph}
中的图形(居中)。这是解决方案 2。article
book
低于
\documentclass[tikz]{standalone}
\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},
}
\begin{tikzpicture}[ 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}},
]
\matrix (orga)
{ 1-1 & & 1-3 & \\ %[1cm] %level 1
2-1 & & 2-3 & \\ %level 2
& 3-2 & & \\ %level 3
4-1 & & 4-3 & \\ [-0.2cm] %level 4
};
%------------------ Flèches -------------------------
% Left
\draw[fleche] (orga-1-1) - - (orga-2-1) ;
\draw[fleche] (orga-2-1) - - (orga-4-1) ;
% Right
\draw[fleche] (orga-1-3) - - (orga-2-3) ;
\draw[fleche] (orga-2-3) - - (orga-4-3) ;
% South
\draw[fleche] (orga-4-3) - - (orga-4-1) ;
\draw[fleche] (orga-4-1.south east) - - (orga-4-3.south west) ;
% From South
%Gauche
%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}
\end{tikzpicture}
\end{document}
答案1
visible on
这是库中附带的nice 样式的 poor-cat 版本beamer-overlay-styles
。您可以为每个元素分配一个类,以控制其可见性。这class={1,3}
意味着元素显示在第一个和第三个覆盖层上。如果您进行 beamer 演示,您可以加载库beamer-overlay-styles
,忘记所有这些class
东西并改用visible on=<1,3>
。但是,如果您不仅更改可见性,而且在不同的幻灯片上有不同的元素,您可能仍然对样式感兴趣recycle bounding box
,就像\pause
和\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}
稍加修改,您就可以将“覆盖”缩小到各自的大小:在覆盖模式下绘制事物,然后仅选择边界框以包含您真正想要的东西。
\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}