1

I'm here again. Here's the thing:

I found a large number of wonderful examples of TikZ-graph on texexample.net. While I nothing relevant to protein except for a DNA genome double helix in TikZ. So I hope to modify it to a alpha helix like follows:

All alpha helices protein

And here are my 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}

I found the structure was terrible just like this:

enter image description here

However, the structure returned to normal when I annotated the code \myprotein{olive} which was relevanted to tikz-3dplot.

enter image description here

So, I wonder is there any clash between tikz-3dplot and text part?

go go
  • 115
  • Your code nests tikzpictures. Most likely this is the reason for your problems. –  Dec 22 '20 at 05:18

1 Answers1

4

The problem is that you nest tikzpictures when you call \myprotein. Once you remove the \begin{tikzpicture} and \end{tikzpicture} you get

\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}

enter image description here