I use the following code to draw a cylinder. How can I fill it with gradient colour to look like the attached image.

\setbeamertemplate{navigation symbols}{}
\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){};

enter image description here

  • Thank you. I could not figure out how to apply this code (which is for upright cylinder) to a horizontally oriented cylinder.
    – Hany
    Commented Sep 16, 2018 at 12:49
  • 1
    for example in the answer tex.stackexchange.com/a/10707/36296 leave out the shape border rotate=90 and you'll get a horizontal cylinder. Commented Sep 16, 2018 at 12:54

1 Answer 1


Based on https://tex.stackexchange.com/a/10707/36296

\node [draw,
  name=nodename, % Can be defined arbitrarily
  alias=cyl, % Will be used by the ellipse to reference the cylinder
  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),
  (\p1) ellipse (\n2 and \n1);


enter image description here


Not the answer you're looking for? Browse other questions tagged .