4

Can shapes be incorporated into one drawing; as making the green rectangles appear as the red drawing, so no lines appear between them, and filling them as a one unit? and incorporating a circle into a series of lines to become one drawing, centered vertically to each other? Can text be added to different parts?

\documentclass{article}
\usepackage{tikz}

\begin{document}

% begin incorporate shapes centred vertically

\begin{tikzpicture}[rounded corners=8pt,ultra thick]
\draw[blue, outer color=green, ,inner color=green!35] (0,0)rectangle+(2.,.7);
\draw[blue, outer color=green, ,inner color=green!35,rotate=90] (0,-.6)rectangle+(4,.7);
\draw[blue, outer color=green, ,inner color=green!35] (-.1,3.3)rectangle+(2.,.9);
\draw[blue, outer color=green, ,inner color=green!35] (-.1,1.5)rectangle+(7.5,.8);
\draw[blue, outer color=green, ,inner color=green!35,rotate=90] (2,-4)rectangle+(1.5,.7);
\end{tikzpicture}

\vskip 2cm

\begin{tikzpicture}[rounded corners=8pt,ultra thick]
\draw[red, top color=red, bottom color=red, middle color=red!25]
(0,0)--(0,-1)--(3.5,-1)--(3.5,-1.45)--(-3.5,-1.45)--(-3.5,-2.5)--(-2.5,-2.5)--(-2.5,-3)--(-4,-3)--(-4.,2)--(-2.,2)--(-2.,1)--(-3.5,1)--(-3.5,-1)--(-.5,-1)--(-.5,0)--cycle;
\end{tikzpicture}
% end incorporate shapes

\vskip 2cm

% begin Nerve Cell2
\begin{minipage}[c]{1\textwidth}
\hskip 4cm
{
\begin{tikzpicture}[blue, rounded corners=8pt,ultra thick]
\draw[inner color=yellow, outer color=red] (0,0)circle(.5cm);
\end{tikzpicture}
\vskip -.18cm
\hskip .88cm
\begin{tikzpicture}[blue, rounded corners=8pt,ultra thick]
\draw[top color=red, bottom color=red, middle color=red!25]
(0,0)--(0,-1)--(3.5,-1)--(4.2,-.8)--(3.4,-1.12)--(4.2,-1.1)--(3.4,-1.22)--(4.2,-1.4)--(3.4,-1.34)--(4.2,-1.65)--(3.5,-1.45)--(-3.5,-1.45)--(-4.,-2)--(-3.54,-1.25)--(-4.,-.5)--(-3.5,-1)--(-.5,-1)--(-.5,0)--cycle;
\end{tikzpicture}
}
\end{minipage}
% end Nerve Cell2

\end{document}

incorporate shapes as a one drawing

7
  • 11
    Can it be done? Yeah, probably. With hours of work. Perhaps you'd like to make a start and then the TikZ experts here can lend you a hand when you get stuck?
    – Au101
    Dec 16, 2015 at 4:47
  • Hello cfr , I hope you are interested in my question. I appreciate very much your answers
    – Hany
    Dec 16, 2015 at 8:50
  • 4
    "Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document." Dec 16, 2015 at 9:33
  • @Hany, very nice attempt but it seems it belongs to your another question tex.stackexchange.com/questions/283308/drawing-a-nerve-cell
    – CroCo
    Dec 18, 2015 at 7:55
  • @CroCo. Yes, they both are parts of the drawing I am trying to do.
    – Hany
    Dec 19, 2015 at 5:05

2 Answers 2

2

You can combine Tom Bombadil's \unionclip with Zarko's drawings in the following way. This is obviously just an example: it is up to you to develop the specific combinations you need.

It is generally easier to use relative, rather than absolute coordinates from the beginning when possible. In the case of a pic you might think this doesn't matter as they are always relative, in a sense. But, even then, the use of relative coordinates facilitates various kinds of flexibility, such as making it easier to combine code in different ways e.g. to make another pic or, as here, to specify two related \clips. I've therefore made almost all of Zarko's coordinate's relative as opposed to absolute. Absolute coordinates are used only as anchor points for the clipping paths.

\documentclass[tikz,multi,border=5pt]{standalone}
% from Tom Bombadil's answer: https://tex.stackexchange.com/a/58950/
\usepackage{arrayjobx}
\newcommand{\unionclip}[3]{% number of clippings, clipping commands (connect with &), draw commands
  \newarray\temp%
  \readarray{temp}{#2}%
  \foreach \x in {1,...,#1}%
  { \begin{scope}%
      \pgfmathtruncatemacro{\xt}{\x}%
      \temp(\xt)%
      #3%
    \end{scope}%
  }%
  \delarray\temp%
}
\begin{document}
\begin{tikzpicture}[rounded corners=1.2mm, thick]
  \unionclip{2}{% 
    % based on Zarko's answer: https://tex.stackexchange.com/a/283877/
    \clip
      (0,1.2) coordinate (a-north)-| ++(0.2,-1) -| ++(2.8,-.2) coordinate (a-east) |- ++(-6,-.2) |- ++(1,-1) |- ++(-1.4,-.4) -- ++(0,1.6) coordinate (a-west) |- ++(1.4,2.4) |- ++(-1,-.8) |- ++(2.8,-1.4) |- ++(.2,1);&
    \clip
      ([xshift=35mm]a-east) ++(0,1.2) coordinate (b-north) -| ++(.2,-1) -- ++(3.3,0) -- ++(.7,.4) coordinate (b-east above)  to [out=225, in=175,looseness=4] ++(0,-.45) to [out=195, in=165,looseness=6] ++(0,-.3) to [out=195, in=135,looseness=4] ++(0,-.45) coordinate (b-east below)  -- ++(-.7,.4) -- ++(-3.5,0) coordinate (b-south)       -- ++(-3.5,0) -- ++(-.5,-0.4) coordinate (b-west below) to  [out=45, in=-45,looseness=1.3] ++(0,1.2) coordinate (b-west above)  -- ++(.5,-.4) -| ++(3.3,1) -- cycle;
  }{%
    \fill [top color=red, bottom color=red, middle color=red!25]
    (-4,-2) rectangle (15,2.5);
  }
\end{tikzpicture}
\end{document}

combo-solution

However, you cannot use pics directly in \clips, which is why I've just copied the relevant paths into the \clip commands here. \clip is restricted to simpler things than constructions such as \path and \draw and so on, so it isn't as straightforward as simply turning a \pic into a \clip directly.

[And, as I mentioned before, pic is partially broken in recent versions of PGF/TikZ, especially concerning naming. Since this broke some time ago and the bug has persisted, I assume that the regression is due to other changes and that it is not a simple fix. If so, it will presumably stay broken for the foreseeable future. However, this is pure speculation on my part. I just wouldn't count on its being fixed any time soon.]

Note that even if these were nodes rather than pics, you could not use them directly to clip. Clipping wants closed paths. Nor could you join them in any straightforward way. Again, unless you use a uniform fill etc. - but you can do that with pics, too, of course. Just use the same colour fill for each and don't draw the border so that they join continuously.

The main reason to use \unionclip is that you can apply a shading across the entire combined shape so that the colour changes smoothly. At least, that's the only reason I can think of here. Transparency would be another reason or fading and so on.

1
  • Thank you very very much. I appreciate very much your effort and time spent for your answer.
    – Hany
    Feb 16, 2016 at 4:53
5

I understood, that you like to form set of building blocks of for complex images. For this job seems to be handy small pictures \pic, which you defined in `\tikzset and than use in complex image. Something like this:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning,shapes}
%---------------------------------------------------------------%
\tikzset{mynevro/.style = {
nerve1/.pic = {\path[draw=red, rounded corners=1.2mm, thick,
            top color=red, bottom color=red, middle color=red!25]
        ( 0.0,1.2) coordinate (-north)-| (0.2,0.2) -|
        ( 3.0,0.0) coordinate (-east) |- (-3,-0.2) |- (-2,-1.2) |-
        (-3.4,-1.6) --
        (-3.4,0.0) coordinate (-west) |- (-2,2.4)
        |- (-3,1.6) |- (-0.2,0.2) |- (0,1.2);
                },
nerve2/.pic = {\path[draw=blue, rounded corners=1.2mm, thick,
            top color=orange, bottom color=orange, middle color=orange!25]
        ( 0.0, 1.2) coordinate (-north)       -| ( 0.2,0.2) -- (3.5, 0.2) --
        ( 4.2, 0.6) coordinate (-east above)  to [out=225, in=175,looseness=4]
        ( 4.2, 0.15) to [out=195, in=165,looseness=6]
        ( 4.2,-0.15) to [out=195, in=135,looseness=4]
        ( 4.2,-0.6) coordinate (-east below)  -- ( 3.5,-0.2) --
        ( 0.0,-0.2) coordinate (-south)       -- (-3.5,-0.2) --
        (-4.0,-0.6) coordinate (-west below) to  [out=45, in=-45,looseness=1.3]
        (-4.0, 0.6) coordinate (-west above)  -- (-3.5, 0.2) -| (-0.2, 1.2) --
        cycle;%
        \coordinate (-west) at (-3.8,0);
        \coordinate (-east) at ( 3.8,0);

               },
nerve3/.style = {circle,minimum size=7mm, draw=black,
            inner color=yellow, outer color=red,
            node contents={~}
                },
                            }
         }% end of tikzset
%---------------------------------------------------------------%

    \begin{document}
\begin{tikzpicture}[mynevro]
\pic (A) {nerve1};
    \node[above] at (A-north) {north};
    \node[right] at (A-east)  {east};
    \node[left]  at (A-west)  {west};
\end{tikzpicture}

\bigskip

\begin{tikzpicture}[mynevro,
    node distance = 0mm,
    points/.style = {circle, inner sep=1pt, fill=red},
         pin edge = black
                    ]
\pic (A) {nerve2};
\node[points,pin=45:north, above=of A-north] {};
%
\node[points,pin=45:east above,  above right=of A-east above] {};
\node[points,pin= 0:east,        right=of A-east] {};
\node[points,pin=315:east below, below right=of A-east below] {};
%
\node[points,pin=315:south, below=of A-south] {};
%
\node[points,pin=240:west below, below left=of A-west below] {};
\node[points,pin=180:west,       right=of A-west] {};
\node[points,pin=135:west above, below right=of A-west above] {};
%
\end{tikzpicture}
\bigskip

\begin{tikzpicture}[mynevro,
    node distance = 0mm,
                    ]
\pic (A) {nerve1};
\pic (B) [right=42mm of A-east] {nerve2};
\node[nerve3,above=of A-north];
%
\end{tikzpicture}
    \end{document}

enter image description here

With designed small picture you can almost unlimited compose complex picture. In their positioning in picture you need to take a care width of pic. As they are defined as in above MWE, its anchor is at inner coordinate (0,0).

To pic you can add nodes with text etc relative to coordinates defined for each \pic. This is demonstrated in first two images, where are designates anchors of pic by nodes with anchor names (the first picture) and by nodes with pins with anchor names.

Addendum: The positioning of small pictures is tricky. In this a drawer had to keep in mind that above \pic has origin at internal coordinate (0,0), which is 12 mm below anchor north and 37 mm right from anchor west (see definition of nerve2). Consequently, that nerve2 can follows nerve1 without gap between them, their position should be defined (relatively) as:

\begin{tikzpicture}[mynevro,
    node distance = 0mm,
                    ]
\pic (A) {nerve1};
\pic (B) [right=37mm of A-east] {nerve2};% <-- 
\end{tikzpicture}

In this case the picture is:

enter image description here

As help in composing of nerves into complex images serves the first two images in the first pictures.

There is another problem with pic. As cfr mentioned in her comment: " ... the pic naming is broken and has been for a while. That is, some of the syntax which did work and should work and is in the manual does not work at the moment and hasn't for some time. ..."

10
  • You might want to mention that, although the code you are using does work, the pic naming is broken and has been for a while. That is, some of the syntax which did work and should work and is in the manual does not work at the moment and hasn't for some time. (For example, the seagull code from the manual does not work.)
    – cfr
    Dec 19, 2015 at 23:26
  • I'm not sure this actually answers the question because the question isn't very clear. (I read it as asking something else, but you could easily be correct in your reading.)
    – cfr
    Dec 19, 2015 at 23:27
  • I have similar doubt, is my answer is what OP looking for, on the end I think that a new aspect on his problem can help him to formulate new, more clear question or in the best case even gives framework for his further work. Regarding \pic naming, alas you are right. With \pic I have another problems to: its positioning in picture is not straightforward. As you can see from my third example, I need to consider distance from left border of \pic to its inner coordinate (0,0), what is very annoying. I hope that in next release of TikZ some of those problem will be solved.
    – Zarko
    Dec 19, 2015 at 23:43
  • @Zarko Thank you Zarko. I will try to understand and apply your answer, since I am new to tikz.
    – Hany
    Dec 20, 2015 at 7:04
  • @Zarko Hello Zarko. Thank you very much for your answer. I am very sorry for the delay. I had some personal problems that prevented me from trying your precious answer. It is very helpful. Just one comment, in your mini picture, there were text attached to the drawing; but when applying your code, no text was displayed. Again thank you very much, and I am very sorry for the delay
    – Hany
    Feb 13, 2016 at 4:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .