1

This MWE is just a part of a document, containing many other drawings and text, added to this frame and other frames.

I would like to control the scaling of the defined drawings (xraytube and headtop) when placed in different locations in the document.

I tried including them in miniframes or adding \begin{tikzpicture}[scale=, transform shape], but all my trials failed to include them with different scaling in different locations. How can I control the scaling factor?

\documentclass{beamer} \usetheme{PaloAlto} \setbeamertemplate{navigation symbols}{} \usepackage{tikz} \usetikzlibrary{arrows, arrows.meta, positioning, calc, intersections, decorations.pathreplacing, decorations.pathmorphing, decorations.markings, decorations.fractals, decorations.footprints, shapes, shapes.misc, shapes.symbols, shapes.geometric, patterns, backgrounds, shadows} \usetikzlibrary{fadings, shadings}%for snake % % begin to set all frametitles to bold \setbeamerfont{frametitle}{series=\bfseries} % end to set all frametitles to bold % %begin definition xraytube \def\xraytube {% \def\scl{.4} \def\wda{1}%1.2 \def\wdb{2} \def\wdc{4} % \begin{tikzpicture}[scale=\scl, opacity=1, line width=.05cm, rounded corners=5pt, transform shape] \draw[gray, bottom color=gray, top color=gray!25](-\wda,0) --++(-90:\wdc) --++(180:\wdb) --++(-90:\wdb) --++(0:\wdb) --++(0:\wda) --++(0:\wda)--++(0:\wdb) --++(90:\wdb) --++(180:\wdb) --++(90:\wdc) -- cycle; \draw[gray, top color=gray, bottom color=gray!40](0,-.25) ellipse (1. and 0.5); \end{tikzpicture} }% %end definition xraytube % %begin definition headtop \def\headtop { \begin{tikzpicture}[scale=.8, line width=.05cm, rounded corners=5pt, rotate=0, looseness=1.] \node (o) at (0,0) {}; \node (or) at ([shift={(0.:4.025)}]o.center) {}; \node (ot) at ([shift={(87.:1.)}]o.center) {}; \node (ort) at ([shift={(95.:1.)}]or.center) {}; \node (x) at ([shift={(56.5:3.6)}]o.center) {}; \node (xt) at ([shift={(90:.3)}]x.center) {}; \node (xl) at ([shift={(180:.34)}]x.center) {}; \node (xr) at ([shift={(0:.34)}]x.center) {}; % \draw[brown, bottom color=brown!60!orange!25!white, top color=brown!60] (xl.center) to [out=40, in=-140] (xt.center) to [out=-40, in=140] (xr.center); % \draw[brown, right color=brown!60!orange!25!white, left color=brown!60] (o.center) to [out=-170, in=160] (ot.center); % \draw[brown, left color=brown!60!orange!25!white, right color=brown!60] (or.center) to [out=-10, in=20] (ort.center); % \draw[brown, inner color=brown!60!orange!25!white, outer color=brown!60] (o.center) arc (180:360:2) to[out=90,in=0] (x.center) to[out=180,in=90] (o.center) -- cycle; \end{tikzpicture} }% %end definition headtop \begin{document} % begin frame \begin{frame}[t] \frametitle {xray tube headtop} \vspace {7.5cm} \begin{tikzpicture} \hspace {5cm} \xraytube \end{tikzpicture} \vspace {-10.4cm} \begin{tikzpicture} \hspace {4.96cm} \draw[gray, top color=gray, bottom color=gray, middle color=gray!40] (0,0) rectangle +(5,-.2) node[midway]{.}; \end{tikzpicture} \vspace {1.9cm} \begin{tikzpicture} \hspace {5.2cm} \headtop \end{tikzpicture} \vspace {-6.45cm} \begin{tikzpicture}[decoration={snake, amplitude=.4mm, segment length=3mm, post length=4mm}] \hskip 7.4cm \draw<2>[decorate, red, -latex, line width=.06cm] (0,0) -- ++(90:5.4cm); \hskip .2cm \draw<3>[decorate, blue, -latex, line width=.06cm] (0,0) -- ++(90:5.4cm); \hskip -.4cm \draw<4>[decorate, green, -latex, line width=.06cm] (0,0) -- ++(90:5.4cm); \end{tikzpicture} \end{frame} \end{document} 

enter image description here enter image description here enter image description here enter image description here

0

2 Answers 2

2

You should never nest tikzpictures.


That being said, I would place all your elements in a single tikzpicture. This way you can scale them easily with \begin{ tikzpicture}[scale=...]:

\documentclass{beamer} \usetheme{PaloAlto} \usepackage{tikz} \def\scl{.4} \def\wda{1}%1.2 \def\wdb{2} \def\wdc{4} \def\xraytube{% \begin{scope}[scale=\scl, opacity=1, line width=.05cm, rounded corners=5pt, transform shape,overlay] \draw[gray, bottom color=gray, top color=gray!25](-\wda,0) --++(-90:\wdc) --++(180:\wdb) --++(-90:\wdb) --++(0:\wdb) --++(0:\wda) --++(0:\wda)--++(0:\wdb) --++(90:\wdb) --++(180:\wdb) --++(90:\wdc) -- cycle; \draw[gray, top color=gray, bottom color=gray!40](0,-.25) ellipse (1. and 0.5); \end{scope} } \def\headtop{ \begin{scope}[scale=2*\scl, line width=.05cm, rounded corners=5pt, rotate=0, looseness=1.,overlay] \node (o) at (0,0) {}; \node (or) at ([shift={(0.:4.025)}]o.center) {}; \node (ot) at ([shift={(87.:1.)}]o.center) {}; \node (ort) at ([shift={(95.:1.)}]or.center) {}; \node (x) at ([shift={(56.5:3.6)}]o.center) {}; \node (xt) at ([shift={(90:.3)}]x.center) {}; \node (xl) at ([shift={(180:.34)}]x.center) {}; \node (xr) at ([shift={(0:.34)}]x.center) {}; % \draw[brown, bottom color=brown!60!orange!25!white, top color=brown!60] (xl.center) to [out=40, in=-140] (xt.center) to [out=-40, in=140] (xr.center); % \draw[brown, right color=brown!60!orange!25!white, left color=brown!60] (o.center) to [out=-170, in=160] (ot.center); % \draw[brown, left color=brown!60!orange!25!white, right color=brown!60] (or.center) to [out=-10, in=20] (ort.center); % \draw[brown, inner color=brown!60!orange!25!white, outer color=brown!60] (o.center) arc (180:360:2) to[out=90,in=0] (x.center) to[out=180,in=90] (o.center) -- cycle; \end{scope} }% \begin{document} \begin{frame} \frametitle{xray tube headtop} \centering \begin{tikzpicture} \begin{scope}[yshift=-55] \xraytube \end{scope} \begin{scope}[xshift=-45] \headtop \end{scope} \end{tikzpicture} \end{frame} \begin{frame} \frametitle{xray tube headtop} \centering \begin{tikzpicture}[scale=0.6] \begin{scope}[yshift=-55] \xraytube \end{scope} \begin{scope}[xshift=-45] \headtop \end{scope} \end{tikzpicture} \end{frame} \end{document} 

enter image description here

2
  • Thank you very much for your tips and answer Commented Mar 21, 2024 at 16:55
  • @Hany You're welcome! Commented Mar 21, 2024 at 19:30
1

Here is an option to be able to work with direct coordinates relative to the sheet, using the nodes accessible through the remember picture overlay option, with which we will obtain the current page.center coordinate.

Having these coordinates generated some problems with my method of moving the origin of what I draw using \draw_comand(initial_coordinate)++(xshift, yshift) ... which, for example, move the drawing, but if it has a fill with shading, the shading is enlarged, this is solved by making the drawing at a coordinate (0,0) which will be its anchor point and then in a scope environment perform the respective displacement. Doing this preserves the shadings.

Another thing necessary to work is to generate a grid with the coordinates to be able to obtain the coordinates visually, for that use a drawing definition \HL{position}{Axis_y+_size}{Axis_x+_size}that draws a grid with negative and positive x and y axes with the origin at (0,0) that, thanks to the scope environment, can be placed without problems where indicated in the position argument.

Then to be able to reuse the drawings that you made and that are in definitions, do not forget that you can use arguments, something similar to object and attributes, to use it in harmony with the coordinate axis, the 2 drawings that you made I had to move them so that they are symmetrical from an origin (0,0), that way they can be located and rotated correctly.

In the playground sheet I placed most of the commands and of course using the grid, as you can see in the position definitions I have used the calc library, since everything must necessarily be relative to the point obtained by curent page.center, so as not to be rewriting the entire rename to original using: \coordinate (orig) at (current page.center); that way all drawings can have coordinates relative to the grid origin using $(orig)+(x_shift,y_shift)$, Finally I added the option of being able to place the name to a coordinate of the xraytube object to be able to obtain the coordinates for the rays relative to these points, I also added a command line to be able to find the nodes that have a name, and some variables for styles that allow manage them.

RESULT:

enter image description here

OTHER PAGES:

enter image description here

MWE: IMPORTANT, IT NEEDS TO BE COMPILED TWO TIMES

\documentclass{beamer} \usetheme{PaloAlto} \setbeamertemplate{navigation symbols}{} \usepackage{tikz} \usetikzlibrary{arrows, arrows.meta, positioning, calc, decorations.pathmorphing, backgrounds} \usetikzlibrary{fadings, shadings}%for snake \tikzset{ Amp/.store in=\Amp,Amp=1mm, %Environment variable for amplitude Len/.store in=\Len,Len=2mm, % Variable for segment length. SineArrow/.style={%Decoration definition for SineArrow ->, decorate, decoration={ snake, amplitude=\Amp, segment length=\Len, post length=2mm } }, Head/.style={brown, bottom color=brown!60!orange!25!white, top color=brown!60}, >={Latex} } % % begin to set all frametitles to bold \setbeamerfont{frametitle}{series=\bfseries} \def\HL#1#2#3{%help lines Fom J.Leon V. \HL{position}{Axis_y+_size}{Axis_x+_size} \begin{scope}[shift={(#1)}] \draw[blue!50!white,step=0.2cm,line width=0.2pt] (-#3,-#2) grid (#3,#2); \draw[blue,step=1cm,line width=0.5pt] (-#3,-#2) grid (#3,#2); \pgfmathtruncatemacro{\t}{#3} \foreach \x in {-\t,...,\t} {% \node[fill=white,circle,anchor=center,text=blue!50!black,inner sep=0] at (\x,0) {\tiny\x}; } \pgfmathtruncatemacro{\t}{#2} \foreach \y in {-\t,...,\t} {% \node[fill=white,circle,anchor=center,text=blue!50!black,inner sep=0] at (0,\y) {\tiny\y}; } \end{scope} } %begin definition xraytube \def\xraytube#1#2#3#4#5#6{%\xraytube{position}{width_a}{lenght_a}{lengt_c}{color}{name} \begin{scope}[shift={(#1)}] \draw[gray, bottom color=#5, top color=#5!25] (0,0) coordinate (#6) --++(180:#2/2) |-++(-#4,-#3) arc (90:270:#2/4 and #2/2) -|++(#2+2*#4,#2) -|(0:#2/2)-- cycle; \draw[gray, top color=#5, bottom color=#5!40] (0,0) ellipse (#2/2 and #2/4) (#2/2+#4,-#3-#2/2) ellipse (#2/4 and #2/2); \end{scope} }% %begin definition headtop \def\headtop#1#2#3{ % \headtop{position}{scale}{rotate} % Default \headtop{0.8}{0} \begin{scope}[ shift={(#1)}, scale=#2, transform shape, rotate=#3] \node (o) at (-2,0) {}; %At -2,0 the objet is centered to the origin \node (or) at ([shift={(0.:4.025)}]o.center) {}; \node (ot) at ([shift={(87.:1.)}]o.center) {}; \node (ort) at ([shift={(95.:1.)}]or.center) {}; \node (x) at ([shift={(56.5:3.6)}]o.center) {}; \node (xt) at ([shift={(90:.3)}]x.center) {}; \node (xl) at ([shift={(180:.34)}]x.center) {}; \node (xr) at ([shift={(0:.34)}]x.center) {}; %Drawng Objet \draw[Head] (xl.center) to [out=40, in=-140] (xt.center) to [out=-40, in=140] (xr.center); \draw[Head] (o.center) to [out=-170, in=160] (ot.center); \draw[Head] (or.center) to [out=-10, in=20] (ort.center); \draw[brown, inner color=brown!60!orange!25!white, outer color=brown!60] (o.center) arc (180:360:2) to[out=90,in=0] (x.center) to[out=180,in=90](o.center) -- cycle; \end{scope} }% \begin{document} % begin frame \begin{frame}[t] \frametitle {xray playground} \begin{tikzpicture}[remember picture,overlay] %Use customized help lines to get points from center o the page \HL{current page.center}{4.6}{6.2} \coordinate (orig) at (current page.center); %Drawing target \begin{scope}[shift={($(orig)+(1,2.8)$)}] \draw[gray, top color=gray, bottom color=gray, middle color=gray!40] (0,0) rectangle +(5,-.2) coordinate (target); %some coordinate to find where end te rays. \end{scope} \xraytube{$(orig)+(3.5,-2)$}{1}{1}{1}{gray}{T1} \xraytube{$(orig)+(-2,3)$}{0.25}{0.25}{2}{red}{T2} \xraytube{$(orig)+(-2,2)$}{0.5}{1}{0.25}{blue}{T3} \headtop{$(orig)+(-3,-1)$}{0.25}{-45} \headtop{$(orig)+(-2,-3)$}{0.3}{-85} \headtop{$(orig)+(3.5,0)$}{0.5}{-90} \draw[Len=5mm,Amp=5mm,SineArrow,red,thick] (T1) -- (T1|-target); \draw[Len=10mm,Amp=3mm,SineArrow,blue,thick] (T1)++(3mm,0)coordinate (temp) -- (temp|-target); \draw[Len=15mm,Amp=2mm,SineArrow,green!50!black,thick,dashed] (T1)++(-3mm,0)coordinate (temp) -- (temp|-target); \foreach \k in {o,or,ot,ort,x,xt,xl,xr,target,T1,T2,T3}{\fill[red!50!black] (\k.center) circle (1.5pt)node[anchor=45,scale=0.5,fill=yellow,opacity=0.5]{\k};} % Use to find each node and node name. \end{tikzpicture} \end{frame} \begin{frame}[t] \frametitle {xray tube headtop} \begin{tikzpicture}[remember picture,overlay] %Use customized help lines to get points from center o the page %\HL{current page.center}{4.6}{6.2} \coordinate (orig) at (current page.center); %Drawing target \begin{scope}[shift={($(orig)+(1,3)$)}] \draw[gray, top color=gray, bottom color=gray, middle color=gray!40] (0,0) rectangle +(5,-.2) coordinate (target); %some coordinate to find where end te rays. \end{scope} \xraytube{$(orig)+(3.5,-2.7)$}{0.75}{1}{0.5}{gray}{T1} \headtop{$(orig)+(3.5,-0.5)$}{0.8}{0} \draw<2>[SineArrow,red,thick] (T1) -- (T1|-target); \draw<3>[SineArrow,green!40!black,thick] (T1)++(2mm,0)coordinate (temp) -- (temp|-target); \draw<4>[SineArrow,blue,thick] (T1)++(-2mm,0)coordinate (temp) -- (temp|-target); %\foreach \k in {o,or,ot,ort,x,xt,xl,xr,target,T1,T2,T3}{\fill[red!50!black] (\k.center) circle (1.5pt)node[anchor=45,scale=0.5,fill=yellow]{\k};} % Use to find each node and node name. \end{tikzpicture} \end{frame} \end{document} 
1
  • @J Leon V. Thank you very much for your time and concern. I will look into your code and try to use it. Commented Mar 21, 2024 at 16:56

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.