3
\begin{tikzpicture}
\pgfmathsetmacro{\cubex}{1}
\pgfmathsetmacro{\cubey}{6}
\pgfmathsetmacro{\cubez}{2}
\draw[black, ultra thick,fill=yellow] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle;
\draw[black, ultra thick,fill=yellow] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle;
\draw[black, ultra thick, fill=yellow] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle;
\end{tikzpicture}

I need to add the quotes (like this picture) for each edge of the parallelepiped. Can you help me? Thanks a lot!

enter image description here

Alenanno
  • 37,338
ryuk
  • 2,257

2 Answers2

4

Here's an example with the code you provided, just reuse part of the paths you used to make the 3D shape.

By the way, consider adding a new feature for the corners, so that the shape looks a bit better. To see the difference using regular angles vs changing them to round, see In TikZ when is “line join=miter” the preferrable over “line join=round”?

Output

enter image description here

Code

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}

\tikzset{
    every path/.style={line join=round}
}

\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\cubex}{1}
\pgfmathsetmacro{\cubey}{6}
\pgfmathsetmacro{\cubez}{2}
\draw[black, ultra thick,fill=yellow] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle;
\draw[black, ultra thick,fill=yellow] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle;
\draw[black, ultra thick, fill=yellow] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle;

\draw[ultra thick, |-|] (-2,0,0) -- ++(0,-\cubey,0) node[midway, left] {30cm};
\draw[ultra thick, |-|] (-\cubex,-7,0) -- ++(\cubex,0,0) node[midway, below] {10cm};
\draw[ultra thick, |-|] ++(1.5,-\cubey,0) -- ++(0,0,\cubez) node[midway, below right] {15cm};
\end{tikzpicture}
\end{document}
Alenanno
  • 37,338
2

@Alenanno's approach works perfectly fine. But I thought I'd offer a solution that doesn't take advantage of TikZ's 3D coordinate system. I also illustrate a few different approaches to labeling the sides.

\documentclass[border=6pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{arrows.meta}
\begin{document}

\def\aes{cm*0.25}%%
\def\aeb{\aes*0.6}%%
\def\aepang{30}%% angle for projecting the back of box
\begin{tikzpicture}
  %% Coordinates for the Front
  \coordinate (F1) at (0,0);
  \coordinate (F2) at ($(F1)+(10\aes,0)$);
  \coordinate (F3) at ($(F1)+(0,30\aes)$);
  \coordinate (F4) at (F2|-F3);

  %% Coordinates for the back
  \coordinate (B2) at ($(F2)+(\aepang:15\aeb)$);
  \coordinate (B4) at ($(F4)+($(B2)-(F2)$)$);
  \coordinate (B3) at ($(F3)+($(B2)-(F2)$)$);

  %% Front
  \draw[fill=red!30] (F3) rectangle (F2);
  %% Side
  \draw[fill=red!30] (F2) -- (B2) -- (B4) -- (F4) -- cycle;
  %% Top
  \draw[fill=red!30] (F3) -- (B3) -- (B4) -- (F4) -- cycle;

  \draw[arrows=|-|] ([shift={(\aepang-90:6pt)}]F2) -- node[midway,anchor=north west] {15cm} ([shift={(\aepang-90:6pt)}]B2);
  \draw[arrows=|-|] ([yshift=-6pt]F1)              -- node[midway,below]             {10cm} ([yshift=-6pt]F2);
  \draw[arrows=|-|] ([xshift=-6pt]F1)              -- node[midway,left]              {30cm} ([xshift=-6pt]F3);
\end{tikzpicture}

\end{document}

enter image description here

Here's an approach that uses transform canvas to applying the shifted coordinates. In fact, I've written more as a template which allows easy changes to create each of the rectangular boxes you want.

\documentclass[border=6pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{arrows.meta}
\begin{document}
\def\aesW{10}%% width 
\def\aesD{15}%% depth 
\def\aesH{30}%% height

\def\aes{cm*0.15}%%
\def\aeb{\aes*0.6}%%
\def\aepang{30}%% angle for projecting the back of box
\begin{tikzpicture}[my face color/.style={fill=red!30}]
  %% Coordinates for the Front
  \coordinate (F1) at (0,0);
  \coordinate (F2) at ($(F1)+(\aesW\aes,0)$);
  \coordinate (F3) at ($(F1)+(0,\aesH\aes)$);
  \coordinate (F4) at (F2|-F3);

  %% Coordinates for the back
  \coordinate (B2) at ($(F2)+(\aepang:\aesD\aeb)$);
  \coordinate (B4) at ($(F4)+($(B2)-(F2)$)$);
  \coordinate (B3) at ($(F3)+($(B2)-(F2)$)$);
  \coordinate (B1) at (B2-|B3);

  %% Front
  \draw[my face color] (F3) rectangle (F2);
  %% Side
  \draw[my face color] (F2) -- (B2) -- (B4) -- (F4) -- cycle;
  %% Top
  \draw[my face color] (F3) -- (B3) -- (B4) -- (F4) -- cycle;

  \draw[arrows=|-|,transform canvas={shift={(\aepang-90:6pt)}}] (F2) -- node[midway,anchor=north west] {\aesD cm} (B2);
  \draw[arrows=|-|,transform canvas={yshift=-6pt}]              (F1) -- node[midway,below]             {\aesW cm} (F2);
  \draw[arrows=|-|,transform canvas={xshift=-6pt}]              (F1) -- node[midway,left]              {\aesH cm} (F3);
\end{tikzpicture}

\end{document}

Setting my face color={}, setting the height, width, and depth:

\def\aesW{30}%% width 
\def\aesD{5}%% depth 
\def\aesH{10}%% height

and adding the following lines to the above template

  \foreach \myn in {F1,B2,B3}
  {
    \draw[dashed] (B1) -- (\myn);
  }

allows you to draw

enter image description here

Then in your master document (or another standalone) you can write like the following:

\documentclass[border=6pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}[on grid]
  \node (A)                       {\includegraphics{example_02}};
  \node (B) [right=2.5cm of A.east] {\includegraphics{example_03}};
  \node (C) [below=2.5cm of A.south] {\includegraphics{example_03}};
  \node (D) [right=2.5cm of C.east] {\includegraphics{example_02}};

  \node (D/label) at (D.north west-|B.north west)          {(d)};
  \node (C/label) at (C.north west|-D/label)          {(c)};
  \node (A/label) at (C/label|-A.north west) {(a)};
  \node (B/label) at (B.north west|-A/label) {(b)};

\end{tikzpicture}

\end{document}

to create

enter image description here

A.Ellett
  • 50,533