1

I'm trying to draw a cube similar to the one in the pic, but I don't get the desired result. enter image description here

\documentclass[letterpaper, 12pt]{article}
\usepackage[margin = 1in]{geometry}
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\usepackage{xcolor}
\begin{document}
\begin{tikzpicture}

\draw[dashed] (2,0,0) -- (2,2,0) node[midway,right] {$L$};

\draw [dashed] (0,2,2) -- (0,0,2);

\draw[dashed] (0,0,0) -- (0,2,0);
\draw [dashed] (2,0,2) -- (2,2,2);

\draw[very thick] (0,2,0) -- (0,2,2) -- (2,2,2) -- (2,2,0) -- cycle;
\filldraw[color=gray!40] (0,2,0) -- (0,2,2) -- (2,2,2) -- (2,2,0) -- cycle;

\draw[very thick] (0,0,0) -- (0,0,2) -- (2,0,2) -- (2,0,0) -- cycle;
\filldraw[color=gray!40] (0,0,0) -- (0,0,2) -- (2,0,2) -- (2,0,0) -- cycle;

\end{tikzpicture}
\end{document}

2 Answers 2

1

In your construction, by drawing the dashed lines after filling, we have a figure similar to the one you want.

screenshot

\documentclass[letterpaper, 12pt]{article}
\usepackage[margin = 1in]{geometry}
\usepackage[spanish]{babel}
%\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usetikzlibrary{positioning}
%\usepackage{pgfplots}
%\pgfplotsset{compat=1.15}

\usepackage{xcolor}
\begin{document}
\begin{tikzpicture}


\draw[very thick] (0,2,0) -- (0,2,2) -- (2,2,2) -- (2,2,0) -- cycle;
\filldraw[color=gray!40] (0,2,0) -- (0,2,2) -- (2,2,2) -- (2,2,0) -- cycle;

\draw[very thick] (0,0,0) -- (0,0,2) -- (2,0,2) -- (2,0,0) -- cycle;
\filldraw[color=gray!40] (0,0,0) -- (0,0,2) -- (2,0,2) -- (2,0,0) -- cycle;


\draw[dashed] (2,0,0) -- (2,2,0) node[midway,right] {$L$};

\draw [dashed] (0,2,2) -- (0,0,2);

\draw[dashed] (0,0,0) -- (0,2,0);
\draw [dashed] (2,0,2) -- (2,2,2);
\end{tikzpicture}
\end{document}
1
  • Voting down deserves an explanation. Without explanation this has no meaning other than gratuitous hostility.
    – AndréC
    Commented Jul 27, 2019 at 8:34
3

Like this?

\documentclass[letterpaper, 12pt]{article}
\usepackage[margin = 1in]{geometry}
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{xcolor}

\pgfmathsetmacro{\a}{7} %  
\pgfmathsetmacro{\b}{4} % 
\pgfmathsetmacro{\teta}{125}
\begin{document}
\begin{tikzpicture}[
x={(1cm,0cm)},
y={({cos(\teta)*1cm}, {sin(\teta)*1cm})},
z={(0cm,1cm)},
]
\coordinate (A) at (0,0,0); 
\coordinate (B) at (\a,0,0); 
\coordinate (C) at (\a,\b,0); 
\coordinate (D) at (0,\b,0); 
\begin{scope}[shift={(\b,\a)}]
\coordinate (E) at (0,0,0); 
\coordinate (F) at (\a,0,0); 
\coordinate (G) at (\a,\b,0); 
\coordinate (H) at (0,\b,0);
\end{scope}
\draw[ultra thick,fill=pink] (A) -- (B)  -- (C) -- (D) --cycle;
\draw[ultra thick,fill=pink] (E) -- (F)  -- (G) -- (H) --cycle;
\path (B)--(D)node[midway]{\huge $i$};
\path (F)--(H)node[midway]{\huge $j$};
\draw [ultra thick, dashed](A)--(B)node[midway,below]{\huge $X$};
\draw [ultra thick, dashed](A)--(D)node[midway,left=2mm]{\huge $Y$};
\draw [ultra thick, dashed](D)--(H)node[midway,left]{\huge $L$};
\draw [ultra thick, dashed](A)--(E) (B)--(F) (C)--(G);
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

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