这个MWE只是文档的一部分,包含许多其他图纸和文本,添加到这个框架和其他框架中。
我想控制定义的图纸(xraytube 和 headtop)在放置在文档中的不同位置时的缩放比例。
我尝试将它们包含在 miniframe 中或添加 \begin{tikzpicture}[scale=, transform shape],但我的所有尝试都无法在不同位置以不同的比例包含它们。我该如何控制缩放因子?
\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}
答案1
你永远不应该嵌套 tikzpictures。
话虽如此,我会将所有元素放在一个 tikzpicture 中。这样你就可以轻松地缩放它们\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}
答案2
这里有一个选项,可以使用相对于工作表的直接坐标,使用可通过选项访问的节点remember picture overlay
,我们将通过该节点获得current page.center
坐标。
这些坐标给我移动绘图原点的方法带来了一些问题\draw_comand(initial_coordinate)++(xshift, yshift) ...
,例如,移动绘图,但如果它填充了阴影,阴影就会被放大,这个问题可以通过在将绘图作为(0,0)
其锚点的坐标处进行绘制来解决,然后在scope
环境中执行相应的位移。这样做可以保留阴影。
另一件需要做的事情是生成一个带有坐标的网格,以便能够直观地获得坐标,为此使用一个绘图定义,\HL{position}{Axis_y+_size}{Axis_x+_size}
该定义绘制一个grid
具有负和正 x 轴和 y 轴的图形,原点为 (0,0),由于环境的原因scope
,可以毫无问题地将其放置在position
参数中指示的位置。
然后,为了能够重用您所制作的和定义中的图纸,请不要忘记您可以使用参数,类似于对象和属性的东西,为了与坐标轴协调使用,我必须移动您制作的两张图纸,使它们从原点对称(0,0)
,这样它们就可以正确定位和旋转。
在操场表上,我放置了大多数命令,当然使用了grid
,正如您在位置定义中看到的那样,我使用了calc library
,因为一切都必须相对于通过获得的点curent page.center
,以免将整个重命名为原始使用:\coordinate (orig) at (current page.center);
这样,所有图纸都可以使用相对于网格原点的坐标$(orig)+(x_shift,y_shift)$
,最后我添加了能够将名称放置到xraytube
对象的坐标的选项,以便能够获得相对于这些点的射线的坐标,我还添加了一个命令行以便能够找到具有名称的节点,以及一些允许管理它们的样式变量。
结果:
其他页面:
梅威瑟:重要,需要编译两次
\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}