0

I often need to make of diagrams involving cells and/or other medium complex shapes. At the for this I work with nodes, since they are easy to position and to connect. To make the cell shapes I use additional tikzfigure enviroments within the nodes. See the following minimal example.

This is not optimal and I wonder if there is a simpler solution. I tried \pic put they are less flexible than nodes. Probably \pgfdeclareshape would be the way to go, isn't? But this is a little too complicated for my to figure out. Is there an easy explanation or another solution? The simplest would be to make a tikzstyle for the whole cell.

MWE

\documentclass[]{minimal}
\usepackage{tikz} 
\usetikzlibrary{positioning}
\usetikzlibrary{shapes}

\tikzstyle{cytosol} = [thick, draw=red!60, fill = red!20, ellipse, minimum width=35, minimum height= 22, align=center, rotate = 30]
\tikzstyle{nucleus} = [thick, draw=olive!80, fill = brown!20, circle, minimum width=10, align=center]

\begin{document}
\begin{tikzpicture}
    \node[] (Cell1) {
        \begin{tikzpicture}
            \node[cytosol] at(0,0) (cytosol) {};
            \node[nucleus, shift={(0.15,0.1)}] () at(cytosol) {};
        \end{tikzpicture}{}
    };

    \node[right of= Cell1, xshift = 1 cm] (Cell2) {
        \begin{tikzpicture}
            \node[cytosol, draw=gray!40, fill = gray!60] at(0,0) (cytosol) {};
            \node[nucleus, shift={(0.15,0.1)}] () at(cytosol) {};
        \end{tikzpicture}{}
    };

    \node[right of= Cell2, xshift = 1 cm] (Cell3) {
        \begin{tikzpicture}
            \node[cytosol] at(0,0) (cytosol) {};
            \node[nucleus, shift={(0.15,0.1)}] () at(cytosol) {};
        \end{tikzpicture}{}
    };

    \draw[->] (Cell1) --(Cell2); 
    \draw[->] (Cell2) --(Cell3); 

\end{tikzpicture}
\end{document} 

This results in this picture:

enter image description here

Bernard
  • 271,350
  • Small images pic cross my mind ... – Zarko Mar 17 '20 at 13:46
  • Yes, it is possible to create node "shapes" using \pgfdeclareshape, but everything is done using the basic level commands (\pgfpathmoveto, \pgfpathlineto, etc.) The big decision is whether to include text, and to make the shape expand to fit the text. If not, the code can be much simpler. – John Kormylo Mar 17 '20 at 17:41
  • I don't include text in this kind of nodes. So fitting to text is not necessary. – WitheShadow Mar 17 '20 at 17:55
  • Maybe this answer (ironically coming from a related subject) gets you going? In any case, your current method nests tikzpictures which should be avoided by all means. Also, \tikzstyle is deprecated. –  Mar 18 '20 at 00:48
  • I already had a look at pic and they look really helpful. The one thing that I struggle is, that I don't know how you can easily connect different pics with arrows – WitheShadow Mar 18 '20 at 07:12
  • I just figured out that it is possible to connect nodes within pic with arrows. This could solve my problem. – WitheShadow Mar 18 '20 at 07:58

1 Answers1

2

There are many options to achieve this. You could use pics, as mentioned in the comments, cf. e.g. this answer. Here is a somewhat more exotic possibility: use a path picture.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{chains,shapes.geometric}
\tikzset{cytosol/.style={thick, draw=red!60, fill = red!20, ellipse, minimum
width=35, minimum height= 22, align=center,rotate = 30},
nucleus/.style={path picture={\draw[draw=olive!80,fill = brown!20,#1]
    ([xshift=0.15cm,yshift=0.1cm]path picture bounding box.center) 
     circle[radius=5pt];}}}
\begin{document}
\begin{tikzpicture}
 \begin{scope}[start chain=Cell placed {at={(\tikzchaincount*2,0)}},
    nodes={on chain,join= by {semithick,-stealth}}]
  \node[cytosol,nucleus]{};
  \node[cytosol, draw=gray!40, fill = gray!60,nucleus]{};
  \node[cytosol,nucleus]{};
 \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

As you can see, the option nucleus adds the dot. Other exotic options include append after command.

Please note also that your code nests tikzpicture environments, which really should be avoided, and \tikzstyle is deprecated.

  • Yes, I'm aware of the problem with the nested pictures, this is exactly what I'm trying to avoid. The path picture looks interesting I will have a look at it. – WitheShadow Mar 18 '20 at 07:14