我有一个简单的 Tikz 图,但出于某种原因,我似乎无法修改某些节点的位置,它们始终位于 (0,0)。为什么?
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\draw[draw=black,fill=gray!20] (0,0) rectangle ++(4.8,5);
\draw[draw=black,fill=gray!20] (4.8,5) -- (4.9,4.8)--(4.9,-0.1)--(4.8,0);
\draw[draw=black,fill=gray!20] (0,0) -- (0.1,-0.1)--(4.9,-0.1)--(4.8,0);
\pgfmathsetseed{3}
%% Both of the following are always at (0,0)
\draw plot [smooth cycle, samples=8,domain={1:8}] (\x*360/8+2*rnd:0.1cm+0.1cm*rnd) node at (4,3) {};
\node [cylinder, shape border rotate=90, draw, minimum height=5, minimum width=4,fill=NavyBlue]{} (4.6,4.7);
\end{tikzpicture}
\end{document}
答案1
也许是这样的?
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\draw[draw=black,fill=gray!20] (0,0) rectangle ++(4.8,5);
\draw[draw=black,fill=gray!20] (4.8,5) -- (4.9,4.8)--(4.9,-0.1)--(4.8,0);
\draw[draw=black,fill=gray!20] (0,0) -- (0.1,-0.1)--(4.9,-0.1)--(4.8,0);
\pgfmathsetseed{3}
%% Both of the following are always at (0,0)
\draw[shift={(2.4,2.5)}] plot [smooth cycle, samples=8,domain={1:8},variable=\x]
(\x*360/8+2*rnd:1cm+1cm*rnd);
\node at (4.6,4.7) [cylinder, shape border rotate=90, draw, minimum height=5, minimum width=4,fill=NavyBlue]{};
\end{tikzpicture}
\end{document}