我希望复制(Tikz:绘制 RGB 立方体) 与下面的立方体一起,在 Overleaf 上对顶面角进行着色。我将只使用右角和左角作为侧面。我不确定为什么阴影无法理解诸如“上/下/左/右”之类的参数,而我曾看到过使用它的其他示例。所以不幸的是,我在立方体顶面上只显示一种颜色。
我目前拥有的:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{3d}
\usetikzlibrary{shadings}
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
[cube/.style={very thick,black},
grid/.style={very thin,gray},
axis/.style={->,black,thick}]
\begin{tikzpicture}[scale=0.48,every node/.style={minimum size=1cm},on grid]
\begin{scope}[every node/.append style={yslant=-0.5},yslant=-0.5]
[cube/.style={very thick,black},
axis/.style={->,blue,thick}]
\draw[axis] (5,5,0) -- (-2,-2,0) node[anchor=west]{x};
\shade[right color=red!60, left color=blue!60] (0,0) rectangle +(3,3);
\node at (0.5,2.5) {};
\node at (1.5,2.5) {};
\node at (2.5,2.5) {};
\node at (0.5,1.5) {};
\node at (1.5,1.5) {};
\node at (2.5,1.5) {};
\node at (0.5,0.5) {};
\node at (1.5,0.5) {};
\node at (2.5,0.5) {};
\draw (0,0) grid (3,3);
\end{scope}
\begin{scope}[every node/.append style={yslant=0.5},yslant=0.5]
\draw[axis] (3,0,0) -- (8,-5,0) node[anchor=west]{y};
\shade[right color=green!30,left color=red!30] (3,-3) rectangle +(3,3);
\node at (3.5,-0.5) {};
\node at (4.5,-0.5) {};
\node at (5.5,-0.5) {};
\node at (3.5,-1.5) {};
\node at (4.5,-1.5) {};
\node at (5.5,-1.5) {};
\node at (3.5,-2.5) {};
\node at (4.5,-2.5) {};
\node at (5.5,-2.5) {};
\draw (3,-3) grid (6,0);
\end{scope}
\begin{scope}[every node/.append style={
yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
]
\draw[axis] (3,0,0) -- (8,5,1) node[anchor=west]{z};
% \shade[bottom color=red!30, top color=green!80] (6,3) rectangle +(-3,-3);
\shade[right color=red!80, left color=green!40, top color=red!10, bottom color=green!60] (6,3) rectangle +(-3,-3);
\node at (3.5,2.5) {};
\node at (3.5,1.5) {};
\node at (3.5,0.5) {};
\node at (4.5,2.5) {};
\node at (4.5,1.5) {};
\node at (4.5,0.5) {};
\node at (5.5,2.5) {};
\node at (5.5,1.5) {};
\node at (5.5,0.5) {};
\draw (3,0) grid (6,3);
\end{scope}
\end{tikzpicture}
\end{tikzpicture}
\vspace{-5.5em} % do not remove
\caption{Example caption.}
\label{fig:1}
\end{figure}
\end{document}
我还没搞清楚为什么角落的上/下右/左颜色不适用于此 tikzpicture,但右/左/下/上颜色在这里却有效。我已在代码中将此更改添加到立方体顶部。
答案1
像这样?
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{float} %<----- added
\usepackage{tikz}
\usetikzlibrary{3d}
\usetikzlibrary{shadings}
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
[cube/.style={very thick,black},
grid/.style={very thin,gray},
axis/.style={->,black,thick}]
\begin{scope}[every node/.append style={yslant=-0.5},yslant=-0.5]
[cube/.style={very thick,black},
axis/.style={->,blue,thick}]
\draw[axis] (5,5,0) -- (-2,-2,0) node[anchor=west]{x};
\shade[right color=red!60, left color=blue!60] (0,0) rectangle +(3,3);
\node at (0.5,2.5) {};
\node at (1.5,2.5) {};
\node at (2.5,2.5) {};
\node at (0.5,1.5) {};
\node at (1.5,1.5) {};
\node at (2.5,1.5) {};
\node at (0.5,0.5) {};
\node at (1.5,0.5) {};
\node at (2.5,0.5) {};
\draw (0,0) grid (3,3);
\end{scope}
\begin{scope}[every node/.append style={yslant=0.5},yslant=0.5]
\draw[axis] (3,0,0) -- (8,-5,0) node[anchor=west]{y};
\shade[right color=green!30,left color=red!30] (3,-3) rectangle +(3,3);
\node at (3.5,-0.5) {};
\node at (4.5,-0.5) {};
\node at (5.5,-0.5) {};
\node at (3.5,-1.5) {};
\node at (4.5,-1.5) {};
\node at (5.5,-1.5) {};
\node at (3.5,-2.5) {};
\node at (4.5,-2.5) {};
\node at (5.5,-2.5) {};
\draw (3,-3) grid (6,0);
\end{scope}
\begin{scope}[every node/.append style={
yslant=0.5,xslant=-1},yslant=0.5,xslant=-1
]
\draw[axis] (3,0,0) -- (8,5,1) node[anchor=west]{z};
% \shade[bottom color=red!30, top color=green!80] (6,3) rectangle +(-3,-3);
\shade[lower right=red!80, lower left=green!40, upper right=red!10, upper left=green!60] (6,3) rectangle +(-3,-3);
\node at (3.5,2.5) {};
\node at (3.5,1.5) {};
\node at (3.5,0.5) {};
\node at (4.5,2.5) {};
\node at (4.5,1.5) {};
\node at (4.5,0.5) {};
\node at (5.5,2.5) {};
\node at (5.5,1.5) {};
\node at (5.5,0.5) {};
\draw (3,0) grid (6,3);
\end{scope}
\end{tikzpicture}
\vspace{2.5em} % do not remove
\caption{Example caption.}
\label{fig:1}
\end{figure}
\end{document}