Is this a bug in TikZ? I'm working on an assignment which includes a number of colorful graphics, and for some reason the following code doesn't quite work as expected:
\RequirePackage{luatex85}
\documentclass[tikz]{standalone}
\usepackage{xcolor}
\definecolor{red}{HTML}{DC291E}
\definecolor{blue}{HTML}{04588A}
\definecolor{orange}{HTML}{FA6B00}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{positioning}
\usetikzlibrary{external}
\usepgflibrary{arrows.meta}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}[
axes/.style={node font=\small, every node/.style={fill=white, fill opacity=0.375, text opacity=1}},
edge/.style={densely dashed, line width=0.5pt, shorten >= -2.5mm, color=black!75!white},
dimension/.style={draw, line width=0.5pt, arrows = {Stealth-Stealth}, every node/.style={anchor=mid, midway, fill=white, node font=\footnotesize}},
]
\begin{scope}[axes]
\draw[->] (0, 0) -- (-4, -2) node[below left] {$x$} coordinate(x axis);
\draw[->] (0, 0) -- (5, 0) node[right] {$z$} coordinate(y axis);
\draw[->] (0, 0) -- (0, 5) node[above] {$y$} coordinate(z axis);
\end{scope}
\begin{scope}[name prefix = shape3-]
\coordinate (bottom-right-front) at ({-12/sqrt(20) + 3}, {-6/sqrt(20)});
\coordinate (bottom-left-front) at ({-12/sqrt(20)}, {-6/sqrt(20)});
\coordinate (top-right-front) at ({-12/sqrt(20) + 3}, {-6/sqrt(20) + 1});
\coordinate (top-left-front) at ({-12/sqrt(20)}, {-6/sqrt(20) + 1});
\fill[fill=gray!70!white]
(bottom-right-front) -- ++(0, 1) -- (3, 1) -- (3, 0) -- cycle;
\fill[fill=gray!50!white]
(bottom-left-front) -- ++(3, 0) -- ++(0, 1) -- ++(-3, 0) -- cycle;
\fill[fill=gray!30!white]
(top-left-front) -- ++(3, 0) -- (3, 1) -- (0, 1) -- cycle;
\draw[line width=0.5pt, gray!10!white]
(top-right-front) -- (3, 1)
(top-left-front) -- ++(3, 0) -- ++(0, -1);
\draw[line width=0.5pt, gray]
(0, 1) -- (top-left-front) -- ++(0, -1) -- ++(3, 0) -- (3, 0) -- (3, 1);
\end{scope}
\begin{scope}[name prefix = shape2-]
\coordinate (bottom-left-front) at ({-4/sqrt(20)}, {-2/sqrt(20) + 1});
\coordinate (bottom-right-front) at ({-4/sqrt(20) + 3}, {-2/sqrt(20) + 1});
\fill[fill=orange!80!white]
(bottom-left-front) -- ++(3, 0) -- ++(0, 2) -- ++(-3, 0) -- cycle;
\fill[fill=orange!60!gray]
(bottom-right-front) -- ++(0, 2) -- (3, 3) -- (3, 1) -- cycle;
\draw[line width=0.5pt, orange!50!black]
(bottom-left-front) -- ++(3, 0) -- (3, 1)
(bottom-left-front) -- ++(0, 2)
(3, 1) -- (3, 3);
\end{scope}
\begin{scope}[name prefix = shape1-]
\coordinate (bottom-left-front) at ({-4/sqrt(20)}, {-2/sqrt(20) + 3});
\coordinate (bottom-right-front) at ({-4/sqrt(20) + 3}, {-2/sqrt(20) + 3});
\coordinate (top-left-front) at ({-4/sqrt(20)}, {-2/sqrt(20) + 4.5});
\coordinate (top-left-back) at (0, 4.4);
\fill[fill=blue!80!white] (bottom-left-front) -- ++(3, 0) -- ++(-3, 1.5) -- cycle;
% WHY YOU NO FILL?
\fill[fill=blue!65!white] (3, 3) node {a} -- (top-left-back) node {b} -- (top-left-front) node {c} -- (bottom-right-front) node {d} -- cycle;
% THIS WORKS BUT POINTS ARE SAME AS NAMED COORDINATES
% \fill[fill=blue!65!white] (3, 3) node {a} -- (0, 4.4) node {b} -- ({-4/sqrt(20)}, {-2/sqrt(20) + 4.5}) node {c} -- (bottom-right-front) node {d} -- cycle;
\draw[line width=0.5pt, blue!50!black]
(3, 3) -- (0, 4.4) -- (top-left-front) -- ++(0, -2);
\draw[line width=0.5pt, blue!50!orange!50!black]
(bottom-left-front) -- ++(3, 0) -- (3, 3);
\end{scope}
\draw[edge] (shape3-bottom-right-front) -- ++(1, 0) coordinate (shape3-x);
\draw[edge] (shape3-bottom-right-front) -- ({-16/sqrt(20) + 3}, {-8/sqrt(20)}) coordinate (shape3-y);
\draw[edge] (shape3-top-left-front) -- ({-16/sqrt(20)}, {-8/sqrt(20) + 1}) coordinate (shape3-z);
\draw[edge] (shape2-bottom-left-front) -- ++(-1, 0) coordinate (shape2-x);
\draw[edge] (shape1-bottom-left-front) -- ++(-1, 0) coordinate (shape1-x);
\draw[edge] (shape1-top-left-front) -- ++(-1, 0) coordinate (shape1-zf);
\draw[edge] (shape1-top-left-back) -- ++(-1, 0) coordinate (shape1-zb);
\draw[dimension] (shape3-x) -- (4, 0) node[inner xsep=0] {\SI{60}{\mm}};
\draw[dimension] (shape3-y) -- ++(-3, 0) node {\SI{60}{\mm}};
\draw[dimension] (shape3-z) -- ++(0, -1) node {\SI{20}{\mm}};
\draw[dimension] (shape2-x) -- (shape1-x) node {\SI{40}{\mm}};
\draw[dimension] (shape1-x) -- (shape1-zf) node {\SI{30}{\mm}};
\draw[dimension] (shape1-zf) -- (shape1-zb) node[above=5pt] {\SI{20}{\mm}};
\end{tikzpicture}
\end{document}
The blue triangular shape should be filled in a slightly lighter shade on its top surface, but when I use named coordinates it doesn't quite work. I had similar quirks rendering the gray box, but changing the order of the coordinates seemed to fix that. I can't fix it with the blue shape, however.
I wanted to speed up compilation by doing the mathematics as little as possible, and named coordinates seemed to be the answer, especially when the drawing requires dimensioning of all the shapes.
\begin{scope}[name prefix = ...]
. This cause, that each line between given coordinates is drawn as separate line, consequently, you can not fill straight lines. If you deletename prefix = ...
, then all works. I can't judge, if this is bug or intended feature.myedge
what many people do (i prefer short names, because I'm lazy for typing :-( ).