我有两张图形想要合并为一张,但我更想把它们放在文本中,如下所示:
\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{lipsum}
\begin{document}
\lipsum[66]
\begin{figure}[h]
\centering
...
\end{figure}
\lipsum[66]
\end{document}
我的图表代码如下:
\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usepackage[spanish,es-noshorthands]{babel}
\begin{document}
\begin{tikzpicture}
\draw[-stealth] (-1,0) -- (2.5,0) node[below]{$u$};;
\draw[-stealth] (0,-1) -- (0,2.5) node[left]{$v$};
\draw[blue] (-0.8,2)--(2.3,2);
\draw[blue] (-0.8,0.5)--(2.3,0.5);
\draw[red] (2,-0.8)--(2,2.3);
\draw[red] (0.5,-0.8)--(0.5,2.3);
\node at (0,2) [blue, font=\footnotesize, below left]{$1$};
\node at (0,0.5) [blue, font=\footnotesize, below left]{$1$};
\node at (2,0) [red, font=\footnotesize, below left]{$1$};
\node at (0.5,0) [red, font=\footnotesize, below left]{$1$};
\end{tikzpicture}
\end{document}
和
\documentclass[tikz,border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16,width=10cm}
\tikzset{declare function={torusx(\u,\v,\R,\r)=cos(\u)*(\R + \r*cos(\v));
torusy(\u,\v,\R,\r)=(\R + \r*cos(\v))*sin(\u);
torusz(\u,\v,\R,\r)=\r*sin(\v);
vcrit1(\u,\th)=atan(tan(\th)*sin(\u));% first critical v value
vcrit2(\u,\th)=180+atan(tan(\th)*sin(\u));% second critical v value
vtest(\u,\v,\az,\el)=sin(-vcrit1(\u-\az,\el)+\v);
disc(\th,\R,\r)=((pow(\r,2)-pow(\R,2))*pow(cot(\th),2)+%
pow(\r,2)*(2+pow(tan(\th),2)))/pow(\R,2);% discriminant
umax(\th,\R,\r)=ifthenelse(disc(\th,\R,\r)>0,asin(sqrt(abs(disc(\th,\R,\r)))),0);
}}
\pgfplotsset{visible stretch/.style={restrict expr to domain={vtest(atan2(rawy,rawx),%
ifthenelse(veclen(rawx,rawy)>\R,asin(rawz/\r),180-asin(rawz/\r)),\pgfkeysvalueof{/pgfplots/view/az},\pgfkeysvalueof{/pgfplots/view/el})}{-0.05:1.1}},
hidden stretch/.style={restrict expr to
domain={vtest(atan2(rawy,rawx),%
ifthenelse(veclen(rawx,rawy)>\R,asin(rawz/\r),180-asin(rawz/\r)),\pgfkeysvalueof{/pgfplots/view/az},\pgfkeysvalueof{/pgfplots/view/el})}{-1.1:0.05}}}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\R}{2}
\pgfmathsetmacro{\r}{1}
\pgfplotsset{view={35}{60},axis lines=none}
\begin{axis}[]
\pgfplotsinvokeforeach{0,10,...,350}
{\addplot3[samples y=0,domain=0:361,smooth,samples=71,ultra thin,gray!30]
({torusx(x,#1+x/12,\R,\r)},
{torusy(x,#1+x/12,\R,\r)},
{torusz(x,#1+x/12,\R,\r)});
\addplot3[samples y=0,domain=0:360,smooth,samples=71,ultra thin,gray!30]
({torusx(#1,x,\R,\r)},
{torusy(#1,x,\R,\r)},
{torusz(#1,x,\R,\r)});
}
\pgfplotsinvokeforeach{0,10,...,350}
{\addplot3[samples y=0,domain=0:361,smooth,samples=71,visible stretch,very
thin,gray!50]
({torusx(x,#1+x/12,\R,\r)},
{torusy(x,#1+x/12,\R,\r)},
{torusz(x,#1+x/12,\R,\r)});
\addplot3[samples y=0,domain=0:360,smooth,samples=71,visible stretch,very
thin,gray!50]
({torusx(#1,x,\R,\r)},
{torusy(#1,x,\R,\r)},
{torusz(#1,x,\R,\r)});}
\addplot3[samples y=0,domain=0:360,smooth,samples=71,opacity=0.6,
red,very thick,dashed]
({torusx(-90,x,\R,\r)},
{torusy(-90,x,\R,\r)},
{torusz(-90,x,\R,\r)});
\addplot3[samples y=0,domain=0:360,smooth,samples=71,visible
stretch,red,very thick]
({torusx(-90,x,\R,\r)},
{torusy(-90,x,\R,\r)},
{torusz(-90,x,\R,\r)});
\addplot3[samples y=0,domain=0:360,smooth,samples=71,opacity=0.6,
red,very thick,dashed]
({torusx(0,x,\R,\r)},
{torusy(0,x,\R,\r)},
{torusz(0,x,\R,\r)});
\addplot3[samples y=0,domain=0:360,smooth,samples=71,visible
stretch,red,very thick]
({torusx(0,x,\R,\r)},
{torusy(0,x,\R,\r)},
{torusz(0,x,\R,\r)});
\addplot3[samples y=0,domain=0:360,smooth,samples=71,opacity=0.6,
blue,very thick,dashed]
({torusx(x,0,\R,\r)},
{torusy(x,0,\R,\r)},
{torusz(x,0,\R,\r)});
\addplot3[samples y=0,domain=0:360,smooth,samples=71,visible
stretch,blue,very thick]
({torusx(x,0,\R,\r)},
{torusy(x,0,\R,\r)},
{torusz(x,0,\R,\r)});
\addplot3[samples y=0,domain=0:360,smooth,samples=71,opacity=0.6,
blue,very thick,dashed]
({torusx(x,80,\R,\r)},
{torusy(x,80,\R,\r)},
{torusz(x,80,\R,\r)});
\addplot3[samples y=0,domain=0:360,smooth,samples=71,visible
stretch,blue,very thick]
({torusx(x,80,\R,\r)},
{torusy(x,80,\R,\r)},
{torusz(x,80,\R,\r)});
\end{axis};
\end{tikzpicture}
\end{document}
我希望结果是这样的:
答案1
不确定我是否理解正确了你的问题...如果你想要将两个图放在一起,只需将它们放在一起即可。你可以使用baseline
垂直对齐选项,或者你可以查看这里。
我将您的圆环图(计算量很大)保存在一个名为的文件中torus.pdf
。然后您只需将两个图形放在同一行上:
\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16,width=10cm}
\usepackage{lipsum}
\usepackage[spanish,es-noshorthands]{babel}
\begin{document}
\lipsum[66]
\begin{figure}[h]
\centering
\begin{tikzpicture}[baseline=-1cm]
\draw[-stealth] (-1,0) -- (2.5,0) node[below]{$u$};;
\draw[-stealth] (0,-1) -- (0,2.5) node[left]{$v$};
\draw[blue] (-0.8,2)--(2.3,2);
\draw[blue] (-0.8,0.5)--(2.3,0.5);
\draw[red] (2,-0.8)--(2,2.3);
\draw[red] (0.5,-0.8)--(0.5,2.3);
\node at (0,2) [blue, font=\footnotesize, below left]{$1$};
\node at (0,0.5) [blue, font=\footnotesize, below left]{$1$};
\node at (2,0) [red, font=\footnotesize, below left]{$1$};
\node at (0.5,0) [red, font=\footnotesize, below left]{$1$};
% Add the arrow!
\draw[thick, ->] (3, 1.5) to[bend left] ++(2,0);
\end{tikzpicture}
\includegraphics[scale=0.6]{torus.pdf}
\end{figure}
\lipsum[66]
\end{document}
但请注意,如果您希望图表始终处于该位置,则不应该使用figure
---该环境是为了漂浮的人物。在这种情况下,只需使用center
环境,否则,如果没有空间容纳图形,它就会移动。