我又来了。事情是这样的:
我在texexample.net. 虽然我除了TikZ 中的 DNA 基因组双螺旋。所以我希望将其修改为如下的 alpha 螺旋:
以下是我的 MWE:
\documentclass{book}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\begin{document}
\tikzset{helix part/.style n args={2}{insert path={
plot[smooth,variable=\x,domain=-90+#1*180:90+#1*180,
samples=11] ({\pgfkeysvalueof{/tikz/helix/radius}*cos(\x)},
{\x*(\pgfkeysvalueof{/tikz/helix/stretch}*\pgfkeysvalueof{/tikz/helix/radius}/360)+#2},{-\pgfkeysvalueof{/tikz/helix/radius}*sin(\x)})
-- plot[smooth,variable=\x,domain=90+#1*180:-90+#1*180,
samples=11]
({\pgfkeysvalueof{/tikz/helix/radius}*cos(\x)},
{\x*(\pgfkeysvalueof{/tikz/helix/stretch}*\pgfkeysvalueof{/tikz/helix/radius}/360)+\pgfkeysvalueof{/tikz/helix/width}+#2},{-\pgfkeysvalueof{/tikz/helix/radius}*sin(\x)})
}},helix/.is family,
helix/.cd,
radius/.initial=3,stretch/.initial=3,width/.initial=1.5}
\tdplotsetmaincoords{90}{105}
\newcommand{\myprotein}[1]{%
\begin{tikzpicture}[tdplot_main_coords]
\begin{scope}[scale=.1]
rectangle (20,1.1*\pgfkeysvalueof{/tikz/helix/radius});
\foreach \X in {0,2,...,8}
{
\path[top color=#1!60!black,bottom color=#1!30,middle color=#1,
helix part={\X}{0}];
}
\foreach \X in {1,3,...,9}
{
\path[top color=#1!30,bottom color=#1!60!black,middle color=#1,
helix part={\X}{0}];
}
\end{scope}
\end{tikzpicture}
}
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST
\begin{tikzpicture}
\fill (0,0) ellipse (2 and 1);
\myprotein{olive}
\end{tikzpicture}
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST
\end{document}
我发现结构很糟糕,就像这样:
\myprotein{olive}
然而,当我注释与 tikz-3dplot 相关的代码时,结构恢复正常。
所以,我想知道 tikz-3dplot 和文本部分之间是否存在冲突?
答案1
问题是,tikzpicture
调用 时嵌套了\myprotein
。一旦删除 ,\begin{tikzpicture}
就会\end{tikzpicture}
得到
\documentclass{book}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\begin{document}
\tikzset{helix part/.style n args={2}{insert path={
plot[smooth,variable=\x,domain=-90+#1*180:90+#1*180,
samples=11] ({\pgfkeysvalueof{/tikz/helix/radius}*cos(\x)},
{\x*(\pgfkeysvalueof{/tikz/helix/stretch}*\pgfkeysvalueof{/tikz/helix/radius}/360)+#2},{-\pgfkeysvalueof{/tikz/helix/radius}*sin(\x)})
-- plot[smooth,variable=\x,domain=90+#1*180:-90+#1*180,
samples=11]
({\pgfkeysvalueof{/tikz/helix/radius}*cos(\x)},
{\x*(\pgfkeysvalueof{/tikz/helix/stretch}*\pgfkeysvalueof{/tikz/helix/radius}/360)+\pgfkeysvalueof{/tikz/helix/width}+#2},{-\pgfkeysvalueof{/tikz/helix/radius}*sin(\x)})
}},helix/.is family,
helix/.cd,
radius/.initial=3,stretch/.initial=3,width/.initial=1.5}
\tdplotsetmaincoords{90}{105}
\newcommand{\myprotein}[2][]{%
\begin{scope}[tdplot_main_coords,scale=.1,#1]
rectangle (20,1.1*\pgfkeysvalueof{/tikz/helix/radius});
\foreach \X in {0,2,...,8}
{
\path[top color=#2!60!black,bottom color=#2!30,middle color=#2,
helix part={\X}{0}];
}
\foreach \X in {1,3,...,9}
{
\path[top color=#2!30,bottom color=#2!60!black,middle color=#2,
helix part={\X}{0}];
}
\end{scope}}
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST
\begin{tikzpicture}
\fill (0,0) ellipse (2 and 1);
\myprotein{olive}
\end{tikzpicture}
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST
\end{document}