我是 Tikz 新手,想画一个带有 16 个圆形节点的圆。每次滑动增量都会向右或向左移动到下一个节点(同时使用这两个示例应该没问题),同时突出显示它(突出显示应该在当前位置/节点附近)。有人能帮我实现这个吗?附上绘图示例:
谢谢
编辑:这是一个好的开始,但我需要圆形节点而不是文本,每次突出显示一个节点(用蓝色)(当前位置),并且节点移动可以是右或左:
\documentclass{report}
\usepackage{tikz,calc}
\begin{document}
\begin{tikzpicture}
\foreach \a in {1,2,...,17}{
\draw (\a*360/17: 4cm) node{angle \a};
}
\end{tikzpicture}
\end{document}
答案1
我想这就是你所追求的。
\documentclass{beamer}
\usepackage{tikz}
% define a counter
\newcount\CircNum
% macro to hold a color name
\newcommand\Clr{black}
\begin{document}
\begin{frame}
% set up an animation, \CircNum changes from 1 to 17
% with each frame
\animatevalue<1-17>{\CircNum}{1}{17}
\begin{tikzpicture}
% draw the main circle
\node [circle, draw, minimum size=8cm] (c) {};
\foreach \a in {1,2,...,17}{
% if \a is equal to \CircNum, set the color to blue
% otherwise set it to black
\ifnum\a=\the\CircNum
\renewcommand\Clr{blue}
\else
\renewcommand\Clr{black}
\fi
% make a new node for the small circles
\node[\Clr, % with the color defined by the macro
draw, thick, % draw the outline
fill, % fill it
minimum size=5mm, % set the size
circle, % circular shape
label={[\Clr]\a*360/17+180:\a} % add the number on the inside
] at (c.\a*360/17) % position it on the edge of the main circle
{};
}
\end{tikzpicture}
\end{frame}
\end{document}
以下是 PDF 的前三张幻灯片:
答案2
欢迎来到 TeX.SE!
这是一个借鉴的解决\int_step_variable:nnnNn
方案expl3
:
\documentclass{beamer}
\usepackage{expl3}
\usepackage{tikz}
\ExplSyntaxOn
% Borrow a loop macro from expl3
\cs_set_eq:NN \intstepvariable \int_step_variable:nnnNn
\ExplSyntaxOff
\begin{document}
\begin{frame}{Circles in circle}
\begin{center}
\begin{tikzpicture}
\def\nsteps{10}
\def\bigcircleradius{3cm}
\def\smallcirclewidth{0.5cm}
% The big circle
\node[circle, minimum width=2*\bigcircleradius, draw] (C) {};
% The small circles and their labels
\intstepvariable{0}{1}{\nsteps - 1}{\i}{% {init}{step}{final}{variable}
\pgfmathsetmacro{\angle}{90 - \i*360/\nsteps}
\pgfmathsetmacro{\otherside}{\angle+180}
\pgfmathsetmacro{\iplusone}{int(\i+1)}
\pgfmathsetmacro{\iplustwo}{int(\i+2)}
\uncover<\iplustwo-> {
\node[circle, draw, minimum width=2*\smallcirclewidth,
label=\otherside:\iplusone] at (C.\angle) {};
}
\uncover<\iplustwo> { % fill one small circle per frame
\node[circle, fill=red!20, minimum width=2*\smallcirclewidth]
at (C.\angle) {};
}
}
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
...
...
注意:作为以下代码的替代:
\pgfmathsetmacro{\iplustwo}{int(\i+2)}
(...)
\uncover<\iplustwo-> { (...) }
\uncover<\iplustwo> { (...) }
假设 e-TeX 扩展可用,则可以使用:
\uncover<\the\numexpr \i+2\relax-> { (...) }
\uncover<\the\numexpr \i+2\relax> { (...) }
现在,让我们重新进行相同的beamer
演示,但使用更直接的顺序(小圆圈的角度分别为 1*360/10、2*360/10、...、10*360/10 度)。主代码的编写方式与上一个示例略有不同:它使用两个循环和\pause
中的宏beamer
,而第一个示例在一个循环中完成所有操作,并且仅使用\uncover
。
\documentclass{beamer}
\usepackage{expl3}
\usepackage{tikz}
\ExplSyntaxOn
% Borrow a loop macro from expl3
\cs_set_eq:NN \intstepvariable \int_step_variable:nnnNn
\ExplSyntaxOff
\begin{document}
\begin{frame}{Circles in circle}
\begin{center}
\begin{tikzpicture}
\def\nsteps{10}
\def\bigcircleradius{3cm}
\def\smallcirclewidth{0.5cm}
% The big circle
\node[circle, minimum width=2*\bigcircleradius, draw] (C) {};
% The filled circles: highlight a single small circle on each frame starting
% from frame 2.
\intstepvariable{2}{1}{\nsteps+1}{\i}{% {init}{step}{final}{variable}
\pgfmathsetmacro{\angle}{(\i-1)*360/\nsteps}
\uncover<\i>{
\node[circle, fill=red!20, minimum width=2*\smallcirclewidth]
at (C.\angle) {};
}
}
% The unfilled circles and their labels
\intstepvariable{1}{1}{\nsteps}{\i}{% {init}{step}{final}{variable}
\pgfmathsetmacro{\angle}{\i*360/\nsteps}
\pgfmathsetmacro{\otherside}{\angle+180}
\pause
\node[circle, draw, minimum width=2*\smallcirclewidth, label=\otherside:\i]
at (C.\angle) {};
}
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
...
...