Is ist possible to apply a shading to a path perpendicular to it's current tangent.

I want to draw some kind of 3d-pipe. My question is related to this question. I want to draw 3d-molecules and I am struggeling with how to draw the bonds between the atoms.

I'd like to have something like

\draw[bond color=red; bond width=15pt] (atom1) -- (atom2);

The result should be a pole from coordinate atom1 to coordinate atom2. Pole means a rectangle with a length of the distance beween atom1 and atom2 and a height of 15pt filled with a shade red-white-red along the height axis.

I could actually do that using \shade and shading angle but then I'd have to calculate the shading angle myself depending on the coordinates of atom1 and atom2.

Any suggestions for that?


  • 1
    Can you fill in the missing details with the code and possibly the wrong output?
    – percusse
    Sep 7, 2014 at 12:59

1 Answer 1


Ideally a dedicated decoration could be used (similar to the one that the mindmap library provides for connecting concepts), but here is a simple example using the show path construction decoration.

The shading is applied manually to (a) illustrate how it can be done (b) bypass the default process of clipping the shading to the center quarter.



\tikzset{shading bar/.style args={#1 thick from #2 to #3}{
  decoration={show path construction,
  lineto code={
    % Set the colors.
    % Manually apply the shading.
    % As the bar is a rectangle, scale the shading (which is 100bp x 100bp).
    % Other bar shapes would other adjustments before applying the shading.
    % Although the shading is a (scaled) rectangle the
    % bounding box needs to be updated to the correct size
    % which is done here using clipping.
  }}, decorate

\draw (0,0) grid (5,5);
\draw [shading bar=5mm thick from red to orange] (0,0) -- (3,2);     
\draw [shading bar=5mm thick from blue to cyan] (0,2) -- (2,5); 
\draw [shading bar=10mm thick from green to yellow] (3,5) -- (5,0); 


enter image description here

  • Thanks for your really helpful answer. I could modify your code in a way that it suits my needs. Sep 9, 2014 at 19:56

You must log in to answer this question.

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