I am using tikz to draw multiple cubes. I want to achieve my expected result as bellow
However, the main difficulty is that locates cube inside and center of the cube and making a connection between them. Currently, I am using manually setting the coordination point. Could you help me to do it?
The online code at https://www.overleaf.com/8937330rhwcmbfhzdvx This is my modified code based on how to draw parallelepiped and cube with latex?
\documentclass[border=5pt, multi, tikz]{standalone}
\usetikzlibrary{quotes,arrows.meta}
\tikzset{
annotated cuboid/.pic={
\tikzset{%
every edge quotes/.append style={midway, auto},
/cuboid/.cd,
#1
}
\draw [every edge/.append style={pic actions, densely dashed, opacity=.5}, pic actions]
(0,0,0) coordinate (o) -- ++(-\cubescale*\cubex,0,0) coordinate (a) -- ++(0,-\cubescale*\cubey,0) coordinate (b) edge coordinate [pos=1] (g) ++(0,0,-\cubescale*\cubez) -- ++(\cubescale*\cubex,0,0) coordinate (c) -- cycle
(o) -- ++(0,0,-\cubescale*\cubez) coordinate (d) -- ++(0,-\cubescale*\cubey,0) coordinate (e) edge (g) -- (c) -- cycle
(o) -- (a) -- ++(0,0,-\cubescale*\cubez) coordinate (f) edge (g) -- (d) -- 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,
width=10,
height=10,
depth=10,
units=cm,
scale=.1,
}
\begin{document}
\begin{tikzpicture}
\pic [fill=gray!20, text=green!50!black, draw=black] at (4,-2) {annotated cuboid={width=6, height=20, depth=15, units=mm}};
\pic [fill=gray!20, text=green!50!black, draw=black] at (4,-2.7) {annotated cuboid={width=2, height=4, depth=3, units=m}};
\pic [fill=gray!20, text=green!50!black, draw=black] at (5,-2) {annotated cuboid={width=6, height=20, depth=15, units=mm}};
\pic [fill=gray!20, text=green!50!black, draw=black] at (4.8,-2.7) {annotated cuboid={width=2, height=2, depth=2, units=m}};
\pic [fill=gray!20, text=green!50!black, draw=black] at (5.5,-2.3) {annotated cuboid={width=3, height=10, depth=7, units=m}};
\end{tikzpicture}
\end{document}


line, that sets the "line style". Addingline=dashedwill make the lines of the cuboid dashed lines,line=dottedwill make dotted line etc. – Apr 05 '17 at 05:18picdefinition. If I want to remove the dash line in the cube. Do I need to make a new pic or just add one more argument – John Apr 05 '17 at 05:25densely dashedin theevery edgecommand. You change these lines using a variable like\cubelinethat defaults todraw(ordensely dashedetc). – Apr 05 '17 at 05:43backline. You will needbackline/.store in=\cubeblineand\cubbline=densely dashedin the/cuboid/.cdblock and then replacedensely dashedwith\cubeblineinappend stylecommand. Finally, to use it writeannotated cuboid={backline=draw, ...}etc. – Apr 05 '17 at 06:07backlineequal to the fill colour. For example,backline=orange!20will completely remove the lines from the orange cube. Sorry, I misunderstood and thought by "remove" you meant "remove the dashes" rather than "remove the line". Silly of me! (Btw, overleaf is pretty cool!) – Apr 05 '17 at 07:04