Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

There is already a predefined shading for spherical objects, which is invoked via the "ball" option, but I haven't found a way to switch its color from the default blue to red when using it outside of the "tikzpicture" environment:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations,decorations.pathreplacing}
\begin{document}
\pgfdeclaredecoration{balls}{initial}
{
  \state{initial}[width=\pgfdecoratedpathlength/floor(\pgfdecoratedpathlength/5pt)]
  {
    \pgfpathmoveto{\pgfpoint{1pt}{0pt}}
    \pgfusepath{}
    \pgfpathcircle{\pgfpoint{0pt}{2pt}}{2.5pt}
    \pgfshadepath{ball}{0}{color=red}
    \pgfusepath{}
  }
  \state{final}
  {
    \pgfpathmoveto{\pgfpointdecoratedpathlast}
  }
}
\begin{tikzpicture}
\draw[decorate, decoration={balls}, color=red](0, 0) -- (2, 0);
\end{tikzpicture}
\end{document}

What is the correct way to achieve this?

share|improve this question

closed as too localized by percusse, Kurt, Qrrbrbirlbel, Tom Bombadil, Thorsten Oct 12 '12 at 6:09

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Hi Penguin, welcome to the site. Are you perhaps looking for ball color=red? –  Jake Sep 27 '12 at 15:33
    
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. –  lockstep Sep 27 '12 at 15:35
    
Well, I've tried to use the "ball color=red" flag, it didn't result in changing the color to red no matter where I've put it. Could you maybe give me a hint where to put this question in order to see an effect? –  Penguin Nurse Sep 27 '12 at 16:21
2  
@PenguinNurse: Ah, I might be misunderstanding the quesiton. I used \draw[decorate, decoration={balls}, ball color=red](0, 0) -- (2, 0);, which worked, but you want to define the color within your \pgfdeclaredecoration, correct? –  Jake Sep 27 '12 at 16:23
    
That's actually perfect. Your solution works fine for me, although it might create redundancy for people using the decoration many times. –  Penguin Nurse Sep 28 '12 at 7:45

Browse other questions tagged or ask your own question.