0

I used the following code, from the answers to this question and this question, to draw a Spirograph figure

\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}

enter image description here

There is a white space to the left of the tikzpicture. I am trying to shift the whole drawing to the left to use this unused space.

I tried \begin{scope}[xshift=-2cm] , \begin{scope}[shift={(180:2cm)}] and \tikzset{shift={(-2,0)}} , but they did not work.

Also is it possible to simplify the code for shifting {scope}.

Hany
  • 4,709
  • 2
    A tikzpicture is treated like a simple character. Therefore, your picture is aligned on frame like a simple a. The problem is that the figure is too large to fit in one frame. You'll have to scale down the figure to show it, or design an smaller one. – Ignasi Jan 09 '20 at 08:23
  • why this drawing is too heavy? – enthu Jan 09 '20 at 10:17
  • There is enough space to the left of the frame. If I can shift it to the left a little, it will fit the frame. – Hany Jan 09 '20 at 11:03
  • You could change the margins for this slide. In this case, you might be interested in Gonzalo Medina's answer (https://tex.stackexchange.com/users/3954/gonzalo-medina) that you can find following this link https://tex.stackexchange.com/a/160827/204552. – Lu Cables Jan 09 '20 at 11:24

1 Answers1

0

Is this what you want:

enter image description here

To do this I have rescaled the tikzpicture environment so that the image fits and used \hspace{-2em} to move the environment a little to the left.

In terms of simplifying the shifting code, you can use a \foreach loop. Here is the updated code:

\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}