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.

I've been using pstricks for a long time and feel very much at home there. But, recently I decided I want to learn tikz since that seems to integrate better with beamer. However, I keep running into road blocks. While the manual can be useful, it also gives me headaches for things that would be straight-forward in pstricks but have a completely different (and for me, non-intuitive) approach in tikz.

For example, I want to use pgfkeys to set the style parameters for points: their color, their fill-color, their size. But my invocation of \pgfkeys seem to get ignored. I've tried various approaches. Some lead to errors and other to no effect. Here's what my first attempt at this looked like for which the desired result did not take effect.

\documentclass{article} 
\usepackage[dvipsnames]{xcolor} 
\usepackage{tkz-euclide} 
\pagestyle{empty}
\begin{document}

I would like something that looks like:\vspace{1cm}\par
\begin{tikzpicture}[scale=0.25] 
    \tkzDefPoint(0,0){A}
    \tkzDefShiftPoint[A](70:8){B}
    \tkzDefShiftPoint[A](30:5){C}
    \tkzDefShiftPoint[A](-30:10){D}
    \tkzDefShiftPoint[A](-130:7){E}

    %% first scope
    \begin{scope}[line width=4]
        \tkzDrawPoints[color=blue,fill=red](A,B,C)
    \end{scope}

    %% second scope
    \begin{scope}[line width=2]
        \tkzDrawPoints[color=red,fill=yellow](D,E)
    \end{scope}
\end{tikzpicture}

Here the code is set up more along the lines of how I would like to write
it, but the results are not what I expected.\vspace{1cm}\par
\begin{tikzpicture}[scale=0.25] 
    \tkzDefPoint(0,0){A}
    \tkzDefShiftPoint[A](70:8){B}
    \tkzDefShiftPoint[A](30:5){C}
    \tkzDefShiftPoint[A](-30:10){D}
    \tkzDefShiftPoint[A](-130:7){E}

    %% first scope
    \begin{scope}[line width=4]
        \pgfkeys{/drawpoint/.style={color=blue,fill=red}}
        \tkzDrawPoints(A,B,C)
    \end{scope}

    %% second scope
    \begin{scope}[line width=2]
        \tkzDrawPoints[color=red,fill=yellow](D,E)
    \end{scope}
\end{tikzpicture}

\end{document}

which produces

enter image description here

I've tried to find an answer in the pgfkeys question posted here. But, I'm getting very lost and very confused.

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

Alain Matthes is the author of the tkz-collection. He might not yet be around so I will give an answer a try.

Looking at the file tkz-obj-points.tex of version 1.16c, we can see the definition for \tkzDrawPoints as

\def\tkzDrawPoints{\pgfutil@ifnextchar[{\tkz@drawpts}{\tkz@drawpts[]}} 
%<--------------------------------------------------------------------------–> 
\def\tkz@drawpts[#1](#2){%
\begingroup
\pgfkeys{/drawpoint/.cd}
\pgfqkeys{/drawpoint}{#1}        
\foreach \point in {#2}{%
   \node[point style] at (\point) {};}
\endgroup 
}

We also see

\pgfkeys{/drawpoint/.cd, 
  size/.code    = {\tikzset{point style/.append style={%
                   minimum size = #1*\pgflinewidth}}},
  color/.code    = {\tikzset{point style/.append style={%
                   draw = #1}}}, 
  shape/.code    = {\tikzset{point style/.append style={%
                   shape=#1}}},
  fill/.code    = {\tikzset{point style/.append style={%
                   fill=#1}}}                                     }

So your call to \pgfkeys{/drawpoint... gets over-written every time you use \tkzDrawPoints as this command internally uses the same \pgfkeys drawpoint key. You should use \tikzset instead to style your points like:

%% first scope
    \begin{scope}[line width=4]
        \tikzset{point style/.style={fill=red,draw=blue,minimum size=0.9cm,shape=circle}}
        \tkzDrawPoints(A,B,C)
    \end{scope}

or you can stick with the definition of \tkzDrawPoints:

    %% first scope
    \begin{scope}[line width=4]
%       \tikzset{point style/.style={fill=red,color=blue,minimum size=0.9cm,shape=circle}}
        \tkzDrawPoints[fill=red,color=blue,shape=circle](A,B,C)
    \end{scope}

Note also that you can use size as an option to \tkzDrawPoints. I have to admit that I get unpredictable results with combinations of line width option as you used them in this use-case and size.

Edit 1

You can see the following definition of the key point style in tkz-base.cfg.

\tikzset{point style/.style={draw         = \tkz@euc@pointcolor,
                             inner sep    = 0pt,
                             shape        = \tkz@euc@pointshape,
                             minimum size = \tkz@euc@pointsize*\pgflinewidth,
                             fill         = \tkz@euc@pointcolor!50}} 

You can set the options to your liking. An example is given in the tkz-base manual. Note that the tkz-collection is not an official part of tikz. Rather, it is a collection of tikz-based packages. Here is an example from page 42 of the manual:

\begin{tikzpicture}
\tikzset{point style/.style={%
draw = blue,
inner sep = 0pt,
shape = circle,
minimum size = 6pt,
fill = red!20}}
\tkzDefPoint(1,3){A}
\tkzDefPoint(4,1){B}
\tkzDefPoint(0,0){O}
\tkzDrawPoint(A)
\tkzDrawPoint(B)
\tkzDrawPoint(O)
\end{tikzpicture}

enter image description here

And here it is for your use-case.

%% first scope
\begin{scope}[line width=4]
    \tikzset{point style/.style={%
    draw = blue,
    inner sep = 0pt,
    shape = circle,
    minimum size = 24pt,
    fill = red!20}}
    \tkzDrawPoints[fill=red,color=blue,shape=circle](A,B,C)
\end{scope}

enter image description here

Using the definition of \tkzDrawPoint, you can also specify other shapes. Here is an example from page 43

\begin{tikzpicture}[scale=.5]
\tkzDefPoint(1,3){A}
\tkzDefPoint(4,1){B}
\tkzDefPoint(0,0){O}
\tkzDrawPoint[shape=cross out,size=12,color=red](A)
\tkzDrawPoint[shape=cross,size=12,color=blue](B)
\tkzDrawPoint[size=12,color=green](O)
\tkzDrawPoint[size=12,color=blue,fill=yellow]({2,2})
\end{tikzpicture}

enter image description here

Of course, you can also set the point style options to affect all points.

share|improve this answer
    
Where do I read more to better understand this syntax? There's nothing in the pgf manual about \tikzset{point style/.style=....} otherwise I might have tried it. I had looked at the source code you mention, but again (probably because I'm unfamiliar with the syntax) I didn't realize that the keys were overwriting each other because I thought I was making a different call to them using .style instead of .cd. –  A.Ellett Dec 27 '12 at 22:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.