5

I want to draw a diagram like this:

Puzzle #11

In general, the diagrams in SolveMe Mobiles (section Play)

I suppose I can do with raw code, but I want to do with custom command like: "make horizontal line", "put a hexagonal node", and so on. Is it possible?

Edit :

This is the "raw code" answer, but it's NOT modular:

\begin{tikzpicture}[edge from parent fork down]
  \node{\space}
    child {node [draw, fill=green!20,rectangle] {\space}
        child {node [draw, fill=green!20,rectangle] {\space}}
      }
    child {node [draw, fill=blue!20,circle] {\space}
      child {node [draw, fill=yellow!20] {\space}}
      child {node [draw, fill=red!20] {\space}}
    };
\end{tikzpicture}

It gives me thisenter image description here

which is far away from what I want.

  • 1
    What do you mean with "raw code"? If you mean PGF/TikZ code, maybe that "raw code" can solve your problem in a easier way than you expect. – OSjerick Nov 11 '15 at 13:22
  • 1
    I think it surely is possible. Can you show us how you've started to solve the problem? Even just the lines representing the hanger and bar would be a good start. Please post it here if you have tried! :-) – darthbith Nov 11 '15 at 13:23
  • I guess it is essentially a tree so you could use the trees library or tikz-qtree or forest or the graphs library or something like that. – cfr Nov 11 '15 at 13:34
  • With "raw code" I mean using TikZ without any specific library (eg. tree library) – somenxavier Nov 11 '15 at 14:43
  • You can create pics for the basic building blocks. But unlike nodes, pics do not have anchors, just origins. – John Kormylo Nov 11 '15 at 15:36
6

Your picture is (to me) more easily to draw without use of trees library:

\documentclass[border=3mm,tikz]{standalone}
\usetikzlibrary{chains,
                positioning,
                shadows,
                shapes.geometric
                }

    \begin{document}
\begin{tikzpicture}[
    node distance=5mm and 11mm,
    start chain = going below,
           font = \sffamily,
   basic/.style = {shape=regular polygon, outer sep=0pt, minimum size=1ex, 
                   node contents={~~},  on chain},
     hex/.style = {basic,regular polygon sides=6,
                   top color=teal!30, bottom color=teal!90},
     tri/.style = {basic,regular polygon sides=3,
                   top color=purple!30, bottom color=purple!90,
                   shape border rotate=-180, inner sep=2pt},
     pet/.style = {basic,regular polygon sides=5,
                   top color=orange!30, bottom color=orange!90},
                    ]
\coordinate[left =of {(0,0)}]    (a);
\coordinate[right=of {(0,0)}]    (b);
%
\node (a1) [hex,below=of a];
\node (a2) [hex];
\node (a3) [hex];
    \node (a4) [tri,below=of a3];
    \node[right=0mm of a4.east] {=12};
%
\node (b1) [pet,below=of b];
\node (b2) [tri];
%
\node (c) [hex,left=of a4.west];
\node[right=0mm of c.east] {=5};
        \node (d) [pet,right=of a4.east];
        \node[right] at (d.east) {$=$};
        \node[draw=gray,text width=2em,minimum height=4ex,
              right=5 mm of d.east] {};
% lines
\draw[gray,thick]  (0,0) -- + (0,7mm);
\draw[ultra thick,cap=round] (a) -- (b);
\draw[gray] (a) -- (a1) (a1) -- (a2)    (a2) -- (a3)
            (b) -- (b1) (b1) -- (b2);
\end{tikzpicture}
    \end{document}

Where I use pentagon instead of heart. It can be drawn by pic, however for the first approximation of desired picture should pentagon suffice:

enter image description here

Upgrade: in case dat you very desired to have hearth instead pentagon, than you can drawe heart with pic. With this small pictures a bit more effort is needed for its placements in picture:

\documentclass[border=3mm,tikz]{standalone}
\usetikzlibrary{chains,
                positioning,
                shadows,
                shapes.geometric
                }

    \begin{document}
\begin{tikzpicture}[
    node distance=5mm and 13mm,
    start chain = going below,
           font = \sffamily,
   basic/.style = {shape=regular polygon, outer sep=0pt, minimum size=1ex, 
                   node contents={~~},  on chain},
     hex/.style = {basic,regular polygon sides=6,
                   top color=teal!30, bottom color=teal!90},
     tri/.style = {basic,regular polygon sides=3,
                   top color=purple!30, bottom color=purple!90,
                   shape border rotate=-180, inner sep=2pt},
       pet/.pic = {\path[top color=orange!30, bottom color=orange!90]
                    (0,0)   .. controls (0.0,0.15) and (-0.3,0.20) .. (-0.3,0.4)
                        arc (180:0:0.15)
                        arc (180:0:0.15)
                            .. controls (0.3,0.20) and ( 0.0,0.15) .. (0,0);
                    \coordinate (-south)    at (0,0.02);
                    \coordinate (-north)    at (0,0.4);
                    \coordinate (-west)     at (-0.2,0.3);
                    \coordinate (-center)   at (0,0.3);
                    \coordinate (-east)     at (+0.2,0.3);}
%     pet/.style = {basic,regular polygon sides=5,
%                   top color=orange!30, bottom color=orange!90},
                    ]
\coordinate[left =of {(0,0)}]    (a);
\coordinate[right=of {(0,0)}]    (b);
%
\node (a1) [hex,below=of a];
\node (a2) [hex];
\node (a3) [hex];
    \node (a4) [tri,below=of a3];
    \node[right=0mm of a4.east] {=12};
%
\pic[below=of a1 -| b]  (b1)  {pet};
\node (b2) [tri,below=of b1-south];
%
\node (c) [hex,left=of a4.west];
\node[right=0mm of c.east] {=5};
        \pic [right=17mm of a4.south]  (d) {pet};
        \node[right] at (d-east) {$=$};
        \node[draw=gray,text width=2em,minimum height=4ex,
              right=5 mm of d-east] {};
% lines
\draw[gray,thick]  (0,0) -- + (0,7mm);
\draw[ultra thick,cap=round] (a) -- (b);
\draw[gray] (a) -- (a1) (a1) -- (a2)    (a2) -- (a3)
            (b) -- (b1-north) (b1-south) -- (b2);

    \end{document}

And now the pictures is:

enter image description here

  • thanks. This is exactly what I want: modular design. You just put [hex] and all comes after... ;) – somenxavier Nov 12 '15 at 8:37
4

Just using simple stacks.

\documentclass{article}
\usepackage{marvosym,amssymb,txfonts,stackengine,xcolor,scalerel}
\def\hex{\kern.2pt\textcolor{green!80!black}{\scalerel*{$\Hexasteel$}{)}}}
\def\btd{\textcolor{blue!30!red}{\scalerel*{\blacktriangledown}{)}}}
\def\hrt{\textcolor{orange!80!red}{\scalerel*{\varheartsuit}{)}}}
\def\topstik{\rule{1pt}{10pt}}
\def\stik{\rule{1pt}{5pt}}
\def\hbar{\rule{2.5em}{2pt}}
\setstackgap{S}{-.2pt}
\setstackEOL{\cr}
\begin{document}
\stackunder[15pt]{%
  \stackunder{\Shortstack{\topstik\cr\hbar}}{%
    \Shortunderstack{\topstik\cr\hex\cr\stik\cr\hex\cr\stik\cr\hex}%
    \quad%
    \Shortunderstack{\topstik\cr\hrt\cr\stik\cr\btd}%
  }%
}{%
  $\hex=5\quad\btd=12\quad\hrt=\fbox{\strut~~~~~}$%
}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.