我使用了以下代码,来自以下答案这个问题和这个问题,绘制螺旋图
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{verbatim}
\begin{document}
\tikzset{pics/spiro/.style={code={
\tikzset{spiro/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/spiro/##1}}
\draw[trig format=rad,pic actions]
plot[variable=\t,domain=0:2*pi*\pv{nRotations}, samples=90*\pv{nRotations}+1, smooth cycle]
(
{(\pv{R}+\pv{r})*cos(\t)+\pv{p}*cos((\pv{R}+\pv{r})*\t/\pv{r})},
{(\pv{R}+\pv{r})*sin(\t)+\pv{p}*sin((\pv{R}+\pv{r})*\t/\pv{r})}
);
}},
spiro/.cd,R/.initial=6,r/.initial=-1.5,p/.initial=1,nRotations/.initial=1}
\begin{frame}[t]
\frametitle{Spiro`6,-1.5,1`}
\begin{tikzpicture}[line width=.06cm]
\begin{scope}[scale=.68]
\begin{scope}[xshift=4.5cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
\begin{scope}[xshift=4cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
\begin{scope}[xshift=3.5cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
\begin{scope}[xshift=3cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
\begin{scope}[xshift=2.5cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
\begin{scope}[xshift=2cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
\begin{scope}[xshift=1.5cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
\begin{scope}[xshift=1cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
\begin{scope}[xshift=.5cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
\begin{scope}[xshift=-4.5cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
\begin{scope}[xshift=-4cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
\begin{scope}[xshift=-3.5cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
\begin{scope}[xshift=-3cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
\begin{scope}[xshift=-2.5cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
\begin{scope}[xshift=-2cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
\begin{scope}[xshift=-1.5cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
\begin{scope}[xshift=-1cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
\begin{scope}[xshift=-.5cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
\foreach \scl/\p in {.68/1,.56/.6,.44/.4,.32/.2,.2/.1}
{
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=\scl]{spiro={p=\p}};
}
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}
tikzpicture 左侧有空白。我试图将整个绘图向左移动以使用这个未使用的空间。
我尝试了\begin{scope}[xshift=-2cm]
,\begin{scope}[shift={(180:2cm)}]
和\tikzset{shift={(-2,0)}}
,但是它们没有作用。
另外是否有可能简化移位代码 {scope}
。
答案1
这是你想要的吗:
为此,我重新调整了tikzpicture
环境的比例,以便图像适合,并将\hspace{-2em}
环境稍微向左移动。
为了简化移位代码,可以使用循环\foreach
。以下是更新后的代码:
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{tikz}
\usepackage{verbatim}
\begin{document}
\tikzset{pics/spiro/.style={code={
\tikzset{spiro/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/spiro/##1}}
\draw[trig format=rad,pic actions]
plot[variable=\t,domain=0:2*pi*\pv{nRotations}, samples=90*\pv{nRotations}+1, smooth cycle]
(
{(\pv{R}+\pv{r})*cos(\t)+\pv{p}*cos((\pv{R}+\pv{r})*\t/\pv{r})},
{(\pv{R}+\pv{r})*sin(\t)+\pv{p}*sin((\pv{R}+\pv{r})*\t/\pv{r})}
);
}},
spiro/.cd,R/.initial=6,r/.initial=-1.5,p/.initial=1,nRotations/.initial=1}
\begin{frame}[plain,t]
\frametitle{Spiro`6,-1.5,1`}
\hspace*{-2em}
\begin{tikzpicture}[line width=.06cm,scale=0.5]
\foreach \x in {4.5,4,3.5,3,2.5,2,1.5,1,0.5,-4.5,-4,-3.5,-3,-2.5,-2,-1.5,-1,-0.5} {
\begin{scope}[xshift=\x cm]
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=.68]{spiro={p=1}};
\end{scope}
}
\foreach \scl/\p in {.68/1,.56/.6,.44/.4,.32/.2,.2/.1} {
(0,0) \pic[draw,blue,outer color=blue!80,inner color=blue!10,scale=\scl]{spiro={p=\p}};
}
\end{tikzpicture}
\end{frame}
\end{document}