我是 TikZ 新手,我正在尝试“动画化”连续读取代表数学函数的曲线上的值。目的是逐步实现视觉增强,以集中注意力于我的学生。
在这种精确的状态下,联合代码编译成功。取消注释第 57 行至第 65 行,这将再次编译(但如果您开始尝试直接编译未注释的第 57 行至第 65 行,则不会编译)。现在取消注释两次的行,代码不会编译。我没有足够的技能来理解原因。我希望有人能够解释原因,最好找到解决方法或更好的方法来实现我的目标。提前谢谢!
[编辑] 该问题似乎与角度选项有关。
\draw [->, >=latex, very thick,color=blue!60] (xO) to[out=80,in=100] (yO) ;
\draw [->, >=latex, very thick,color=blue!60] (fxO) to[out=280,in=260] (fyO) ;
似乎能让这个事情发挥作用。 [/编辑]
问候,
纳齐尔特
\documentclass{beamer}
\usepackage{mathrsfs,tikz}
\usetikzlibrary{arrows,arrows.meta,bending}
\makeatletter
\renewcommand*{\@textcolor}[3]{%
\protect\leavevmode
\begingroup
\color#1{#2}#3%
\endgroup
}
\makeatother
\newcommand{\mathcolor}[2][green]{\relax\ifmmode\textcolor{#1}{#2}\else\textcolor{#1}{$#2$}\fi}
\newcommand{\mr}[1]{\mathcolor[red]{#1}}
\newcommand{\mg}[1]{\mathcolor{#1}}
\tikzstyle{every picture}+=[remember picture]
\begin{document}
\begin{frame}
Bla \pause Bla \pause
\begin{center}
\begin{tikzpicture}
% Garder une figure stable avec Beamer / empêcher les dessins de sauter :
% http://tex.stackexchange.com/questions/61260/keep-a-fragmented-tikz-image-at-the-same-place-on-a-beamer-slide
% http://tex.stackexchange.com/questions/18704/how-can-i-fix-jumping-tikz-pictures-in-beamer
\path[use as bounding box] (-5,-1) rectangle(6,5);
% La graduation 1 horizontale
\alt<4>{\draw [very thick, red] (1,-.75ex) -- node [below=.3ex] {$1$} (1,.75ex) ; }{\draw [very thick] (1,-.75ex) -- node [below=.3ex] {$1$} (1,.75ex) ; }
\draw [very thick] (-.6ex,1) -- node [left=.3ex] {$1$} (.6ex,1) ;
% Le grille
\draw[help lines, color=gray, dashed] (-.2,-.2) grid (4.1,4.1);
% Les axes
\draw [-Stealth,ultra thick] (-.2,0)--(4.1,0) node[below] {$x$} ;
\draw[-Stealth,ultra thick] (0,-.2)--(0,4.1) node[left] {$y$};
% La courbe
\draw [very thick, blue] plot [smooth] coordinates {(0,0) (1,4) (2.5,1) (4,2)} ;
% Le nom de la courbe
\node [blue] at (3.5,2) {$\mathscr{C}_f$} ;
% Les points de la courbe
\foreach \pos/\point in {(0,0)/O, (1,4)/A, (2.5,1)/B, (4,2)/C}{\draw node[green,label={[color=green,xshift=-.8ex,yshift=1ex]280:\point} ]% below:$\point$]
at \pos {\Large +}; }
% Les affichages successifs
% Le point O
\uncover<3->{\node [right] at (-3,4) { $O( \tikz[baseline] { \node[anchor=base] (xO) { \alt<3>{\mg{0}}{$0$} } ; } \,;
\tikz[baseline] { \node[anchor=base] (yO) { \alt<3>{\mr{0}}{$0$} } ; }
)$ } ;
\node [right] at (-3,3) { $f( \tikz[baseline] { \node[anchor=base] (fxO) { \alt<3>{\mg{0}}{$0$} } ; } ) =
\tikz[baseline] { \node[anchor=base] (fyO) { \alt<3>{\mr{0}}{$0$} } ; }
$ } ;
% \alt<3>{\draw [->, >=latex, very thick,color=blue!60] (xO) to[out=90,in=90] (yO) ;
% \draw [->, >=latex, very thick,color=blue!60] (fxO) to[out=270,in=270] (fyO) ;
% \draw [->, >=latex,very thick,dotted,color=green!80] (fxO) to[out=270,in=270] (0,-.3) ;
% \draw [->, >=latex,very thick,dotted,color=red!80] (fyO) to[out=0,in=180] (-.3,0) ;
% \draw node[green,label={[color=white,xshift=-.8ex,yshift=1ex,opacity=.75]280:O}] at (0,0) {\Large +} ;
% \node[green,below right] at (0,0) {$0$} ;
% \node[red,above left] at (0,0) {$0$} ; }
% {}
}
% % \uncover<4->{\draw [->, >=latex, very thick, dashed, color=blue!60] (1,0) -- (1,4) -- (0,4) ;
% % \node [right] at (-3,1) { $A( \tikz[baseline] { \node[anchor=base] (xA) { \alt<4>{\mg{1}}{$1$} } ; } \,;
% % \tikz[baseline] { \node[anchor=base] (yA) { \alt<4>{\mr{4}}{$4$} } ; }
% % )$ } ;
% % \node [right] at (-3,0) { $f( \tikz[baseline]{ \node[anchor=base] (fxA) { \alt<3>{\mg{1}}{$1$} } ; } ) =
% % \tikz[baseline]{ \node[anchor=base] (fyA) { \alt<3>{\mr{4}}{$4$} } ; }
% % $ } ;
% % \alt<4>{\draw [->, >=latex, very thick,color=blue!60] (xA) to[out=90,in=90] (yA) ;
% % \draw [->, >=latex, very thick,color=blue!60] (fxA) to[out=270,in=270] (fyA) ; }
% % {}
% % }
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
答案1
嵌套tikzpicture
通常意味着麻烦。有时它可以工作,但如果它中断了,您不能抱怨他们没有警告您。因此,它应该只作为最后的手段。在这种情况下,如果tikzmark
使用库来支持\subnode{}{}
语法,代码会更安全、更简单。第一个参数是名称。第二个参数是内容。
请注意,有关子节点的信息始终落后一次编译。因此,如果在计算中使用子节点之间的距离,则可能会在第一次编译时出错,因为默认情况下所有子节点都位于一个位置。因此,您很容易最终除以零,而 TikZ 无法(毫不奇怪)做到这一点。
这是带有子节点的示例。我还进行了更新,以使用\tikzset
语法,而不是已弃用的语法\tikzstyle
。
\documentclass{beamer}
\usepackage{mathrsfs,tikz}
\usetikzlibrary{arrows,arrows.meta,bending,tikzmark}
\makeatletter
\renewcommand*{\@textcolor}[3]{%
\protect\leavevmode
\begingroup
\color#1{#2}#3%
\endgroup
}
\makeatother
\newcommand{\mathcolor}[2][green]{\relax\ifmmode\textcolor{#1}{#2}\else\textcolor{#1}{$#2$}\fi}
\newcommand{\mr}[1]{\mathcolor[red]{#1}}
\newcommand{\mg}[1]{\mathcolor{#1}}
\tikzset{% update syntax
every picture/.append style = {remember picture},
}
\begin{document}
\begin{frame}
Bla \pause Bla \pause
\begin{center}
\begin{tikzpicture}
% Garder une figure stable avec Beamer / empêcher les dessins de sauter :
% http://tex.stackexchange.com/questions/61260/keep-a-fragmented-tikz-image-at-the-same-place-on-a-beamer-slide
% http://tex.stackexchange.com/questions/18704/how-can-i-fix-jumping-tikz-pictures-in-beamer
\path[use as bounding box] (-5,-1) rectangle(6,5);
% La graduation 1 horizontale
\alt<4>{\draw [very thick, red] (1,-.75ex) -- node [below=.3ex] {$1$} (1,.75ex) ; }{\draw [very thick] (1,-.75ex) -- node [below=.3ex] {$1$} (1,.75ex) ; }
\draw [very thick] (-.6ex,1) -- node [left=.3ex] {$1$} (.6ex,1) ;
% Le grille
\draw[help lines, color=gray, dashed] (-.2,-.2) grid (4.1,4.1);
% Les axes
\draw [-Stealth,ultra thick] (-.2,0)--(4.1,0) node[below] {$x$} ;
\draw[-Stealth,ultra thick] (0,-.2)--(0,4.1) node[left] {$y$};
% La courbe
\draw [very thick, blue] plot [smooth] coordinates {(0,0) (1,4) (2.5,1) (4,2)} ;
% Le nom de la courbe
\node [blue] at (3.5,2) {$\mathscr{C}_f$} ;
% Les points de la courbe
\foreach \pos/\point in {(0,0)/O, (1,4)/A, (2.5,1)/B, (4,2)/C}{\draw node[green,label={[color=green,xshift=-.8ex,yshift=1ex]280:\point} ]% below:$\point$]
at \pos {\Large +}; }
% Les affichages successifs
% Le point O
\uncover<3->{%
\node [right] at (-3,4) { $O( \subnode{xO}{ \alt<3>{\mg{0}}{$0$} } \,; \subnode{yO}{ \alt<3>{\mr{0}}{$0$} } )$ } ;
\node [right] at (-3,3) { $f( \subnode{fxO}{ \alt<3>{\mg{0}}{$0$} } ) = \subnode{fyO}{ \alt<3>{\mr{0}}{$0$} } $ } ;
\alt<3>{\draw [->, >=latex, very thick,color=blue!60] (xO) to[out=90,in=90] (yO) ;
\draw [->, >=latex, very thick,color=blue!60] (fxO) to[out=270,in=270] (fyO) ;
\draw [->, >=latex,very thick,dotted,color=green!80] (fxO) to[out=270,in=270] (0,-.3) ;
\draw [->, >=latex,very thick,dotted,color=red!80] (fyO) to[out=0,in=180] (-.3,0) ;
\draw node[green,label={[color=white,xshift=-.8ex,yshift=1ex,opacity=.75]280:O}] at (0,0) {\Large +} ;
\node[green,below right] at (0,0) {$0$} ;
\node[red,above left] at (0,0) {$0$} ; }
{}
}
\uncover<4->{%
\draw [->, >=latex, very thick, dashed, color=blue!60] (1,0) -- (1,4) -- (0,4) ;
\node [right] at (-3,1) { $A( \subnode{xA}{ \alt<4>{\mg{1}}{$1$} } \,; \subnode{yA}{ \alt<4>{\mr{4}}{$4$} } )$ } ;
\node [right] at (-3,0) { $f( \subnode{fxA}{ \alt<3>{\mg{1}}{$1$} } ) = \subnode{fyA}{ \alt<3>{\mr{4}}{$4$} } $ } ;
\alt<4>{%
\draw [->, >=latex, very thick,color=blue!60] (xA) to[out=90,in=90] (yA) ;
\draw [->, >=latex, very thick,color=blue!60] (fxA) to[out=270,in=270] (fyA) ;
}
{}
}
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}