2

I have three parallelepipeds. I want to make a nice arrow to connect between them. My expected result is

enter image description here

By using some related code, I defined three cubes as follows:

 \pic [fill=cyan!20, text=green!50!black, draw=black] at (0,0) {annotated cuboid={label=A, width=6, height=20, depth=15, units=mm}};

  \pic [fill=blue!20, text=green!50!black, draw=black] at (4,0) {annotated cuboid={label=B, width=6, height=20, depth=15, units=mm}};

  \pic [fill=red!20, text=green!50!black, draw=black] at (4,4) {annotated cuboid={label=C, width=6, height=20, depth=15, units=mm}};

My problem how we can locate the arrow in middle of cube and generates a bent arrow between cube A and C. Could you help me to do it?

My full code is at https://www.overleaf.com/8941463bmfjrnvmzwkx

\documentclass[11pt]{article}
\usepackage{tikz}
  \usetikzlibrary{quotes,arrows.meta}
  \tikzset{
    annotated cuboid/.pic={
      \tikzset{%
        every edge quotes/.append style={midway, auto},
        /cuboid/.cd,
        #1
      }
      \draw [\cubeline,every edge/.append style={pic actions, \cubeback, opacity=.5}, pic actions]
      (0,0,0) coordinate (o-\cubelabel) -- ++(-\cubescale*\cubex,0,0) coordinate (a-\cubelabel) -- ++(0,-\cubescale*\cubey,0) coordinate (b-\cubelabel) edge coordinate [pos=1] (g-\cubelabel) ++(0,0,-\cubescale*\cubez)  -- ++(\cubescale*\cubex,0,0) coordinate (c-\cubelabel) -- cycle
      (o-\cubelabel) -- ++(0,0,-\cubescale*\cubez) coordinate (d-\cubelabel) -- ++(0,-\cubescale*\cubey,0) coordinate (e-\cubelabel) edge (g-\cubelabel) -- (c-\cubelabel) -- cycle
      (o-\cubelabel) -- (a-\cubelabel) -- ++(0,0,-\cubescale*\cubez) coordinate (f-\cubelabel) edge (g-\cubelabel) -- (d-\cubelabel) -- cycle;
      ;
    },
    /cuboid/.search also={/tikz},
    /cuboid/.cd,
    width/.store in=\cubex,
    height/.store in=\cubey,
    depth/.store in=\cubez,
    units/.store in=\cubeunits,
    scale/.store in=\cubescale,
    label/.store in=\cubelabel,
    line/.store in=\cubeline,
    backline/.store in=\cubeback,
    width=10,
    height=10,
    depth=10,
    units=cm,
    scale=.1,
    line=draw,
    backline=densely dashed,
  }
  \begin{document}
  \begin{tikzpicture}

  \pic [fill=cyan!20, text=green!50!black, draw=black] at (0,0) {annotated cuboid={label=A, width=6, height=20, depth=15, units=mm}};

  \pic [fill=blue!20, text=green!50!black, draw=black] at (4,0) {annotated cuboid={label=B, width=6, height=20, depth=15, units=mm}};

  \pic [fill=red!20, text=green!50!black, draw=black] at (4,4) {annotated cuboid={label=C, width=6, height=20, depth=15, units=mm}};

  \end{tikzpicture}
  \end{document}
  • Are you sure these are cubes? ;o) – Bernard Apr 5 '17 at 10:53
  • Yes. Let see it in online link – John Apr 5 '17 at 10:57
  • I'd call them parallelepipeds… – Bernard Apr 5 '17 at 11:01
  • Thanks for your word. Actually, I do not know exactly the word name. Just multiple cubes. – John Apr 5 '17 at 11:02
  • 1
    Literally, a cube is one of the Platonic solid. That said, I know how to do it with pstricks. I do not know TikZ well enough. – Bernard Apr 5 '17 at 11:05
2

One solution could be to put your cuboids into a node, to get anchor points you can use for start and end points of your arrows.

\documentclass[11pt]{article}
\usepackage{tikz}

\usetikzlibrary{quotes,arrows,arrows.meta}
\tikzset{
annotated cuboid ..
% unchanged code
}

\tikzstyle{cubecontainer}=[outer sep = 0pt, inner sep= 0pt]
\tikzstyle{connectarrow}=[-{Triangle[angle=60:0pt 2]},
                          line width= 10pt, shorten >=3mm,shorten <=3mm]

\begin{document}
\begin{tikzpicture}

\node[cubecontainer] (a) at (0,0) {\cuboid{fill=cyan!20, text=green!50!black, draw=black}
                                  {label=A, width=6, height=20, depth=15, units=mm}};
\node[cubecontainer] (b) at (4,0) {\cuboid{fill=cyan!20, text=green!50!black, draw=black}
                                  {label=A, width=6, height=20, depth=15, units=mm}};
\node[cubecontainer] (c) at (4,4) {\cuboid{fill=cyan!20, text=green!50!black, draw=black}
                                  {label=A, width=6, height=20, depth=15, units=mm}};

\draw [connectarrow]  (a.east) -- (b.west);
\draw (a.north) edge[out=90,in=-180,connectarrow] (c.west);

\end{tikzpicture}
\end{document}

enter image description here

If you want a thighter bending, try to modify the looseness:

\draw (a.north) edge[out=90,in=-180,connectarrow,looseness=1.8] (c.west);

enter image description here

|improve this answer|||||
  • Thanks. So if I have many cubes, it means we need use many node. Is it right? – John Apr 5 '17 at 11:12
  • @user8264 you could use loops for that. Also have a look at my edit, I simplifed the code a little by use of some macros. – thewaywewalk Apr 5 '17 at 11:14
  • Could you make the second arrow more bent arrow as my expected – John Apr 5 '17 at 11:15
  • I saw your edit, It is very nice solution. Just adjust the second arrow more bent way. I will accept it – John Apr 5 '17 at 11:19
  • 1
    @user8264 well 0° is at 3 o'clock, 90 is 12 o'clock, -90 6 o'clock respectively – thewaywewalk Apr 6 '17 at 14:10

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.