0

First, thanks to @JLeonV. providing me the code https://tex.stackexchange.com/a/727125/278762. Below is the output using \documentclass{standalone}:

enter image description here

Problem: When I switch from \documentclass{standalone} to \documentclass{beamer}, the TikZ drawing becomes too large to fit within a frame. See the screenshot below:

enter image description here

To solve this, I decided to scale it down by using scale=0.4. However, the scaling does not work as expected. See the blue arrows (1) and (2) on the screenshot below:

enter image description here

Can anyone help me figure out why scaling doesn't work properly?

Code:

\documentclass{beamer} %% packages \usepackage{ifthen} \usepackage{tikz} \usetikzlibrary{patterns, patterns.meta,backgrounds} \usepackage{helvet} \renewcommand*\familydefault{\sfdefault} % Serif Font %% colors \definecolor{PoleRed}{HTML}{E60000} % Define a custom green color using hex \definecolor{PoleGreen}{HTML}{00CC00} % Define a custom green color using hex % #1 number of teeths % #2 radius intern % #3 radius extern % #4 angle from start to end of the first arc % #5 angle to decale the second arc from the first % #6 inner radius to cut off \newcommand{\ToothedRotorCup}[6]{% (0:#2) \foreach \i [evaluate=\i as \n using {(\i-1)*(360/#1}] in {1,...,#1}{% arc (\n:\n+#4:#2) {[rounded corners=0.5pt] -- (\n+#4+#5:#3) arc (\n+#4+#5:\n+360/#1-#5:#3)} -- (\n+360/#1:#2) }% (0,0) circle[radius=#6]; } \newcommand{\AxiallyMagnetizedRotor}[1]{ \def\initAngleRotorCupI{2.7} \def\initAngleRotorCupII{-0.9} % \pgfmathsetmacro\PosAngleI{\initAngleRotorCupI+#1} \pgfmathsetmacro\PosAngleII{\initAngleRotorCupII+#1} % \begin{scope}[rotate=\PosAngleI] \fill[even odd rule, PoleRed] \ToothedRotorCup{50}{5}{5.3}{1.8}{1.6}{.1}; \end{scope} \begin{scope}[rotate=\PosAngleII] \fill[even odd rule, PoleGreen] \ToothedRotorCup{50}{5}{5.3}{1.8}{1.6}{0.1}; \end{scope} \draw (0,0) -- (90+#1:5.3); } %another way to define draw objets \def\PoleShoeCol[At #1][angle #2][radious #3][color #4][size #5 deg x #6]{ \begin{scope}[shift={(#1)},rotate=#2,transform shape] \fill[#4] (-#5/2*0.4:#3+0.5+0.25) -| (0:#3+#6) |- (0+#5/2*0.4:#3+0.5+0.25); \end{scope} } \def\PoleShoeFeet[At #1][angle #2][radious #3][color #4][arc #5 toes #6]{ \begin{scope}[shift={(#1)},rotate=#2+#5/#6*0.25,transform shape] \fill[#4,rounded corners=2.5] (#5/2-#5/#6*0.5:#3+1) arc (#5/2-#5/#6*0.5:-#5/2:#3+1) \foreach \k [evaluate=\k as \j using {\k+1}]in {1,...,#6}{ -- (-#5/2+#5/#6*\k-#5/#6*1:#3+0.75) -- (-#5/2+#5/#6*\k-#5/#6*0.99:#3+0.5) -- (-#5/2+#5/#6*\k-#5/#6*0.50:#3+0.5) -- (-#5/2+#5/#6*\k-#5/#6*0.49:#3+0.75) } -- (-#5/2+#5/#6*#6-#5/#6*0.49:#3+1) -- cycle; \end{scope} } \newcommand{\Steppermotor}[2]{ \draw[thin](0,-10)--(0,10); \draw[thin](-10,0)--(10,0); \AxiallyMagnetizedRotor{#1} \ifthenelse{#2=0}{ \foreach \a/\b/\c/\d in { 0/PoleRed/A{/}/100, 45/gray!70!black/B/0, 90/PoleGreen/A/100/, 135/gray!70!black/B{/}/0, 180/PoleRed/A{/}/100, 180+45/gray!70!black/B/0, 270/PoleGreen/A/100, 270+45/gray!70!black/B{/}/0% }{ \PoleShoeFeet[At 0,0][angle \a][radious 5][color \b][arc 360/50*6 toes 6] \node[text=white,scale=2.5,label={[scale=1.2,text=\b!50!white,label distance=-.75em]-90:\d \%}] at (\a:7.2){\c}; } }{} \ifthenelse{#2=45}{ \foreach \a/\b/\c/\d in { 0/gray!70!black/A{/}/0, 45/PoleRed/B/100, 90/gray!70!black/A/0, 135/PoleGreen/B{/}/100, 180/gray!70!black/A{/}/0, 180+45/PoleRed/B/100, 270/gray!70!black/A/0, 270+45/PoleGreen/B{/}/100% }{ \PoleShoeFeet[At 0,0][angle \a][radious 5][color \b][arc 360/50*6 toes 6] \node[text=white,scale=2.5,label={[scale=1.2,text=\b!50!white,label distance=-.75em]-90:\d \%}] at (\a:7.2){\c}; } }{} \ifthenelse{#2=90}{ \foreach \a/\b/\c/\d in { 0/PoleGreen/A{/}/100, 45/gray!70!black/B/0, 90/PoleRed/A/100/, 135/gray!70!black/B{/}/0, 180/PoleGreen/A{/}/100, 180+45/gray!70!black/B/0, 270/PoleRed/A/100, 270+45/gray!70!black/B{/}/0% }{ \PoleShoeFeet[At 0,0][angle \a][radious 5][color \b][arc 360/50*6 toes 6] \node[text=white,scale=2.5,label={[scale=1.2,text=\b!50!white,label distance=-.75em]-90:\d \%}] at (\a:7.2){\c}; } }{} \begin{scope}[on background layer] \fill[even odd rule,gray!90] (0,0) circle (10) (0,0) circle (10.5); \fill[even odd rule,gray!70!black] (45/2+45*0:8.5) \foreach \k in {1,...,7} {-- (45/2+45*\k:8.5)} -- cycle (0,0) circle (10) \foreach \r in {1,...,4}{(45+90*\r:9) circle (0.75)}; \foreach \m in {0,...,8}{\PoleShoeCol[At 0,0][angle 45*\m][radious 5.2][color gray!70!black][size 50 deg x 3]} \end{scope} \filldraw[even odd rule,gray] (0,0) circle (0.5) (0,0) circle (1); } \begin{document} % Iterate over the angles and create a new frame for each iteration \foreach \StepAngle/\b in {0/0,1.8/45,3.6/90} { \begin{frame}{Stepper Motor Rotor at $\StepAngle^\circ$} \begin{tikzpicture}[scale=0.4] \Steppermotor{\StepAngle}{\b}; % Call your Steppermotor function for each angle \end{tikzpicture} \end{frame} } \end{document} 
4
  • 1
    scale scales only coordinates. If you want to scale everything (but no line thickness and arrows, by design) you should use scale=0.4, transform shape. This is the safest way of scaling a tikzpicture. If you want to scale everything, your approach is ok. Commented Sep 25, 2024 at 7:20
  • 1
    See tikz.dev/tikz-shapes#sec-17.7 for the details Commented Sep 25, 2024 at 7:26
  • 1
    ok thx a lot Rmano Commented Sep 25, 2024 at 7:33
  • As you are using beamer: \begin{frame}[shrink] \frametitle{Stepper Motor Rotor at $\StepAngle^\circ$} \begin{tikzpicture} \Steppermotor{\StepAngle}{\b}; \end{tikzpicture} \end{frame} Commented Sep 25, 2024 at 8:27

1 Answer 1

0

I was able to figure this out on my own. I used \scalebox{0.4}{...} instead of scale=0.4, and it works perfectly.

Code:

\documentclass{beamer} %% packages \usepackage{ifthen} \usepackage{tikz} \usetikzlibrary{patterns, patterns.meta,backgrounds} \usepackage{helvet} \renewcommand*\familydefault{\sfdefault} % Serif Font %% colors \definecolor{PoleRed}{HTML}{E60000} % Define a custom green color using hex \definecolor{PoleGreen}{HTML}{00CC00} % Define a custom green color using hex % #1 number of teeths % #2 radius intern % #3 radius extern % #4 angle from start to end of the first arc % #5 angle to decale the second arc from the first % #6 inner radius to cut off \newcommand{\ToothedRotorCup}[6]{% (0:#2) \foreach \i [evaluate=\i as \n using {(\i-1)*(360/#1}] in {1,...,#1}{% arc (\n:\n+#4:#2) {[rounded corners=0.5pt] -- (\n+#4+#5:#3) arc (\n+#4+#5:\n+360/#1-#5:#3)} -- (\n+360/#1:#2) }% (0,0) circle[radius=#6]; } \newcommand{\AxiallyMagnetizedRotor}[1]{ \def\initAngleRotorCupI{2.7} \def\initAngleRotorCupII{-0.9} % \pgfmathsetmacro\PosAngleI{\initAngleRotorCupI+#1} \pgfmathsetmacro\PosAngleII{\initAngleRotorCupII+#1} % \begin{scope}[rotate=\PosAngleI] \fill[even odd rule, PoleRed] \ToothedRotorCup{50}{5}{5.3}{1.8}{1.6}{.1}; \end{scope} \begin{scope}[rotate=\PosAngleII] \fill[even odd rule, PoleGreen] \ToothedRotorCup{50}{5}{5.3}{1.8}{1.6}{0.1}; \end{scope} \draw (0,0) -- (90+#1:5.3); } %another way to define draw objets \def\PoleShoeCol[At #1][angle #2][radious #3][color #4][size #5 deg x #6]{ \begin{scope}[shift={(#1)},rotate=#2,transform shape] \fill[#4] (-#5/2*0.4:#3+0.5+0.25) -| (0:#3+#6) |- (0+#5/2*0.4:#3+0.5+0.25); \end{scope} } \def\PoleShoeFeet[At #1][angle #2][radious #3][color #4][arc #5 toes #6]{ \begin{scope}[shift={(#1)},rotate=#2+#5/#6*0.25,transform shape] \fill[#4,rounded corners=2.5] (#5/2-#5/#6*0.5:#3+1) arc (#5/2-#5/#6*0.5:-#5/2:#3+1) \foreach \k [evaluate=\k as \j using {\k+1}]in {1,...,#6}{ -- (-#5/2+#5/#6*\k-#5/#6*1:#3+0.75) -- (-#5/2+#5/#6*\k-#5/#6*0.99:#3+0.5) -- (-#5/2+#5/#6*\k-#5/#6*0.50:#3+0.5) -- (-#5/2+#5/#6*\k-#5/#6*0.49:#3+0.75) } -- (-#5/2+#5/#6*#6-#5/#6*0.49:#3+1) -- cycle; \end{scope} } \newcommand{\Steppermotor}[2]{ \draw[thin](0,-10)--(0,10); \draw[thin](-10,0)--(10,0); \AxiallyMagnetizedRotor{#1} \ifthenelse{#2=0}{ \foreach \a/\b/\c/\d in { 0/PoleRed/A{/}/100, 45/gray!70!black/B/0, 90/PoleGreen/A/100/, 135/gray!70!black/B{/}/0, 180/PoleRed/A{/}/100, 180+45/gray!70!black/B/0, 270/PoleGreen/A/100, 270+45/gray!70!black/B{/}/0% }{ \PoleShoeFeet[At 0,0][angle \a][radious 5][color \b][arc 360/50*6 toes 6] \node[text=white,scale=2.5,label={[scale=1.2,text=\b!50!white,label distance=-.75em]-90:\d \%}] at (\a:7.2){\c}; } }{} \ifthenelse{#2=45}{ \foreach \a/\b/\c/\d in { 0/gray!70!black/A{/}/0, 45/PoleRed/B/100, 90/gray!70!black/A/0, 135/PoleGreen/B{/}/100, 180/gray!70!black/A{/}/0, 180+45/PoleRed/B/100, 270/gray!70!black/A/0, 270+45/PoleGreen/B{/}/100% }{ \PoleShoeFeet[At 0,0][angle \a][radious 5][color \b][arc 360/50*6 toes 6] \node[text=white,scale=2.5,label={[scale=1.2,text=\b!50!white,label distance=-.75em]-90:\d \%}] at (\a:7.2){\c}; } }{} \ifthenelse{#2=90}{ \foreach \a/\b/\c/\d in { 0/PoleGreen/A{/}/100, 45/gray!70!black/B/0, 90/PoleRed/A/100/, 135/gray!70!black/B{/}/0, 180/PoleGreen/A{/}/100, 180+45/gray!70!black/B/0, 270/PoleRed/A/100, 270+45/gray!70!black/B{/}/0% }{ \PoleShoeFeet[At 0,0][angle \a][radious 5][color \b][arc 360/50*6 toes 6] \node[text=white,scale=2.5,label={[scale=1.2,text=\b!50!white,label distance=-.75em]-90:\d \%}] at (\a:7.2){\c}; } }{} \begin{scope}[on background layer] \fill[even odd rule,gray!90] (0,0) circle (10) (0,0) circle (10.5); \fill[even odd rule,gray!70!black] (45/2+45*0:8.5) \foreach \k in {1,...,7} {-- (45/2+45*\k:8.5)} -- cycle (0,0) circle (10) \foreach \r in {1,...,4}{(45+90*\r:9) circle (0.75)}; \foreach \m in {0,...,8}{\PoleShoeCol[At 0,0][angle 45*\m][radious 5.2][color gray!70!black][size 50 deg x 3]} \end{scope} \filldraw[even odd rule,gray] (0,0) circle (0.5) (0,0) circle (1); } \begin{document} % Iterate over the angles and create a new frame for each iteration \foreach \StepAngle/\b in {0/0,1.8/45,3.6/90} { \begin{frame}{Stepper Motor Rotor at $\StepAngle^\circ$} \scalebox{0.4}{\begin{tikzpicture} \Steppermotor{\StepAngle}{\b}; % Call your Steppermotor function for each angle \end{tikzpicture}} \end{frame} } \end{document} 

Output:

enter image description here

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.