How to perfect the line joins?
You can use clip to only draw the inside half of lines along the edges. Of course, lines internal to the clip will be twice as wide.
\documentclass[border=1cm]{standalone}
\usepackage{tikz}
%\usepackage[graphics, active, tightpage]{preview}
%\PreviewEnvironment{tikzpicture}
%!tikz preamble begin
\usetikzlibrary{shapes.geometric, arrows.meta, 3d, calc}
\usepackage{tikz-3dplot}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shapes,positioning, backgrounds, scopes}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
%!tikz preamble end
\begin{document}
\begin{tikzpicture}[>=latex,line join=round,scale=1.5]
\pgfmathsetmacro{\cubex}{5}
\pgfmathsetmacro{\cubey}{1}
\pgfmathsetmacro{\cubez}{5}
\newcommand{\boxcolor}{yellow!20!}
\begin{pgfonlayer}{foreground}
\clip (-\cubex,0,-\cubez) -- (0,0,-\cubez) -- (0,-\cubey,-\cubez) -- (0,-\cubey,0)
-- (-\cubex,-\cubey,0)-- (-\cubex,0,0) -- cycle;
\draw[red!20!] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle;
\draw[red!20!] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle;
\draw[red!20!] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle;
\end{pgfonlayer}
\begin{pgfonlayer}{background}
\clip (-\cubex,0,-\cubez) -- (0,0,-\cubez) -- (0,-\cubey,-\cubez) -- (0,-\cubey,0)
-- (-\cubex,-\cubey,0)-- (-\cubex,0,0) -- cycle;
\draw[fill=\boxcolor] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle;
\draw[fill=\boxcolor] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle;
\draw[fill=\boxcolor] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle;
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
An alternative version without \clip
but also with pgfonlayer
s replaced with scope
s. Note that the \draw[fill=\boxcolor]
were replaced with \fill[\boxcolor]
.
Using \draw[fill=\boxcolor,line cap=round, line join =round]
also works fine.
\documentclass[tikz,border=1cm]{standalone}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[>=latex,scale=1.5,line cap=round, line join =round]
\pgfmathsetmacro{\cubex}{5}
\pgfmathsetmacro{\cubey}{1}
\pgfmathsetmacro{\cubez}{5}
\newcommand{\boxcolor}{yellow!20!}
\begin{scope}
\node at (-0.5*\cubex,-0.5*\cubey,-0.25*\cubez) {\Huge some text};
\draw[red!20!] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle;
\draw[red!20!] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle;
\draw[red!20!] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle;
\end{scope}
\begin{scope}[on background layer={line cap=round, line join =round}]
\fill[\boxcolor] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle;
\fill[\boxcolor] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle;
\fill[\boxcolor] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle;
\end{scope}
\end{tikzpicture}
\end{document}
EDIT Looking back at the pgf-tikz
manual, §45 related to the backgrounds
library, it is explained that the options passed to on background layer
allow to pass options to all the objects inside the scope
, which solves the problem completely.