I have been using the following code to draw cubes for a volume worksheet. Full cubes are no problem but when there are half cubes for a dimension, it places the layer of half cubes in the middle somewhere. I was wondering if someone could help me put the fractional layer at the top for height or on the end for depth or width. I have two questions:
1. Can I make the half sizes go on top or the end
2. Can I refer to the direct height or width rather than the hack I used to get 1 less than the actual so the code fits.
This is what I get.

but I would like the half sizes to go on top.
Maybe I'm getting the whole code macros wrong. Someone help please.
\documentclass[11pt,fleqn]{examdesign}
\usepackage{savesym}
\usepackage{amsmath}
\savesymbol{iint}
\usepackage{txfonts}
\restoresymbol{TXF}{iint}
%%\usepackage{amssymb} causes an error when loaded
\usepackage{pifont}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{xspace}
\SectionFont{\large\sffamily}
\usepackage[shortlabels,inline]{enumitem} %%shortlabels here for matching
\usepackage{tkz-euclide} %%%%%%%%%%%for marking angles
\usetkzobj{all} %%%%%%%%%%%necessary cause using overleaf
\usepackage{tikz,ifthen,tikz-3dplot}
\usepackage[font=scriptsize,hypcap=false]{caption}
\graphicspath{ {./dir1/} }
\usepackage{hyperref}
\Fullpages
\ContinuousNumbering
\ShortKey
%%\NoKey
\DefineAnswerWrapper{}{}
\NumberOfVersions{1}
\IncludeFromFile{foobar.tex}
\class{necessary for examdesign}
%%%%%%%%%%%%%%%%%%%%% tikz set for cube%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\cubelength}{0.93}
\tikzset{
cube/.pic={
\draw[] (0,0,0) -- (0,\cubelength,0) -- (\cubelength,\cubelength,0) -- (\cubelength,0,0) -- cycle;
%draw the back-right of the cube
\draw[] (0,0,0) -- (0,\cubelength,0) -- (0,\cubelength,\cubelength) -- (0,0,\cubelength) -- cycle;
%draw the back-left of the cube
\draw[] (0,0,0) -- (\cubelength,0,0) -- (\cubelength,0,\cubelength) -- (0,0,\cubelength) -- cycle;
%draw the front-right of the cube
\draw[fill=magenta] (\cubelength,0,0) -- (\cubelength,\cubelength,0) -- (\cubelength,\cubelength,\cubelength) -- (\cubelength,0,\cubelength)-- cycle;
%draw the front-left of the cube
\draw[fill=orange] (0,\cubelength,0) -- (\cubelength,\cubelength,0) -- (\cubelength,\cubelength,\cubelength) -- (0,\cubelength,\cubelength) -- cycle;
%draw the top of the cube
\draw[fill=cyan] (0,0,\cubelength) -- (0,\cubelength,\cubelength) -- (\cubelength,\cubelength,\cubelength) -- (\cubelength,0,\cubelength) -- cycle;
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%
%%%BEGIN DOCUMENT
%%%%%
\begin{document}
\begin{scriptsize}
\newcommand{\Depth}{3}
\newcommand{\Height}{3.5}
\newcommand{\Width}{4}
\newcommand{\dcube}{\the\numexpr\Depth-1\relax}
\newcommand{\wcube}{\the\numexpr\Width-1\relax}
\pgfmathsetmacro{\hcube}{(\Height-1)}
\begin{tikzpicture}[scale=1]
\coordinate (A) at (0,0,0);
\coordinate (B) at (\Width,0,0);
\coordinate (C) at (\Width,0,\Depth);
\coordinate (D) at (0,0,\Depth);
\coordinate (E) at (0,\Height,\Depth);
\coordinate (F) at (0,\Height,0);
\coordinate (G) at (\Width,\Height,0);
\coordinate (H) at (\Width,\Height,\Depth);
\draw[fill=red!20,opacity=0.2] (A) -- (B) -- (C) -- (D) -- cycle;% Bottom Face
\draw[fill=gray!50] (F) -- (G) -- (B) -- (A) -- cycle;% Back Face
\draw[fill=gray!30] (A) -- (D) -- (E) -- (F) -- cycle;% Left Face
\draw[fill=gray!30] (B) -- (C) -- (H) -- (G) -- cycle;% Right Face
\draw[] (E) -- (F) -- (G) -- (H) -- cycle;% Top Face
\draw[dashed,gray] (A) -- (F);
\draw[dashed,gray] (D) -- (A) --(B);
\draw[fill=gray!30] (B) -- (C) -- (H) -- (G); %%right face
\draw[fill=none] (C) -- (D) --(E);
\tkzMarkRightAngle[draw=blue,size=.2](C,B,G);
\draw[fill=gray!50] (C) -- (D) -- (E) -- (H) -- cycle;% Front Face
\draw[<->,blue,>=latex]([xshift=4mm]B)--node[fill=white,xshift=3mm]{\Height\text{ cm}}([xshift=4mm]G);
\draw[<->,blue, >=latex]([yshift=-3mm]C)--node[fill=white,yshift=-3mm]{\Width \text{ cm}}([yshift=-3mm]D);
\draw[<->,blue]([xshift=5mm]B)--node[xshift=3mm,yshift=-3mm,fill=white]{\Depth\text{ cm}}([xshift=5mm]C);
\draw[|-|,blue,>=latex]([xshift=-4mm]E)--node[right,fill=white,xshift=-3mm,yshift=0.5mm]{$w$}([xshift=-4mm]F);
\foreach \x in {0,...,\wcube}{
\foreach \y in {0,1,2,\hcube}{
\foreach \z in {0,...,\dcube}{
\pic at (\x,\y,\z) {cube};
}}}
\pic at (0,\Height+2,0) {cube};
\end{tikzpicture}
\end{scriptsize}
\end{document}




scale=1, you could just decrease the scale, e.g.scale=0.6. This does (by default) not change the size of the texts, but scales the distances/coordinates. – Apr 09 '20 at 19:37