我使用以下代码绘制一个圆柱体。如何用渐变色填充它以使其看起来像附图一样。
\documentclass{beamer}
\setbeamertemplate{navigation symbols}{}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{frame}[t]
\frametitle{}
\begin{tikzpicture}[scale=1., transform shape]
\node [cylinder,draw=blue,thick,aspect=2.,minimum height=5cm,minimum width=4cm,shape border rotate=0,cylinder uses custom fill, cylinder body fill=blue!30!white,cylinder end fill=blue!20!white] at (0,0){};
\end{tikzpicture}
\end{frame}
\end{document}
答案1
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc}
\begin{document}
\begin{tikzpicture}
\node [draw,
shape=cylinder,
name=nodename, % Can be defined arbitrarily
alias=cyl, % Will be used by the ellipse to reference the cylinder
aspect=3,
minimum height=3cm,
minimum width=2cm,
bottom color=blue,
top color=blue!70!black,
middle color=blue!50!white, % Has to be called after left color and middle color
outer sep=-0.5\pgflinewidth, % to make sure the ellipse does not draw over the lines
% shape border rotate=90
] at (1,2) {};
\fill [blue!90!black] let
\p1 = ($(cyl.before top)!0.5!(cyl.after top)$),
\p2 = (cyl.top),
\p3 = (cyl.before top),
\n1={veclen(\x3-\x1,\y3-\y1)},
\n2={veclen(\x2-\x1,\y2-\y1)}
in
(\p1) ellipse (\n2 and \n1);
\end{tikzpicture}
\end{document}