5

I am drawing a database icon that is made of two cylinder shapes using TikZ. When I add a shadow, the shadows of the two cylinders overlap, and the shadow becomes darker in the overlapping area. The somewhat-MWE below illustrates the problem.

I have tried using transparency groups both within the definition of \dbicon and around the invocation of \dbicon. No luck. What am I doing wrong?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shadows}

\newcommand{\dbpart}[1]{
    \node[drop shadow,draw, cylinder, shape aspect=1.5, inner sep=0.3333em, 
    rotate=90, minimum width=1cm, minimum height=0.45cm] (cyl) at (0,#1) {};
}
\newcommand{\dbicon}{
    \begin{tikzpicture}
      \dbpart{0cm}%
      \dbpart{0.4cm}%
    \end{tikzpicture}
}

\begin{document}
\begin{tikzpicture}
  \node[inner sep=0pt] {
      \dbicon
  };
\end{tikzpicture}

\end{document}

result

krlmlr
  • 12,530
  • I have redone your MWE, you should try to refrain from using any other class than the standard available classes. This ensures that people can easily compile your example. Remark, your nested \newcommand was not necessary, I have moved it out. – nickpapior Feb 06 '12 at 14:01
  • Thank you. I wanted to keep dbpart invisible outside where it's used, that's the reason for the nesting. – krlmlr Feb 06 '12 at 14:03
  • As new user without image posting privileges simply include the image as normal and remove the ! in front of it to turn it into a link. A moderator or another user with edit privileges can then reinsert the ! to turn it into an image again. – Tobi Feb 06 '12 at 14:04

1 Answers1

4

The problem is that a shadow has a default opacity of 0.5 this means that overlapping regions will have increased color fill.

What you need to decide is whether this approach really is the right way of drawing that.

If you just want to remove the overlapping region then use:

\newcommand{\dbpart}[1]{
    \node[drop shadow={opacity=1.0},draw, cylinder, shape aspect=1.5, inner sep=0.3333em, 
    rotate=90, minimum width=1cm, minimum height=0.45cm] (cyl) at (0,#1) {};
}

which will not do additional color on overlapping regions. You might need to adjust the colors afterwards. You can then add fill=gray!20!white in next to the group of the drop shadow.

enter image description here

However that will yield overlapping borders and shadow effects. In your case I think you are better fit with creating a custom node shape and adding different colors on top and sides, or add more space.

nickpapior
  • 17,275