3

Perhaps a stupid mistake but the results are different, why ? I want the nodes on a horizontal line. If I comment \pgfqkeys{/LX}{#1} then the result is fine (the nodes are on horizontal line)

\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\pgfkeys{/LX/.cd,
        frac/.store in              = \Xfrac, %not used
        frac                        = 0,
        /LX/.search also            = {/tikz}, 
}  

\def\labelX[#1](#2,#3){%
\pgfqkeys{/LX}{#1}% ok if I comment this line
\foreach \p in {#2,...,#3}{%
    \path[shift = {(\p,0)}] (0pt,5 pt)--(0pt,-5 pt) 
                            node[/LX/.cd,#1]{\p};}
    \ifnum\Xfrac=1 \node at (0,1){Test frac =1};
    \else \node at (0,1){Test frac =0};
    \fi
}

\def\labelXb[#1](#2,#3){%
\pgfqkeys{/LX}{#1}
\foreach \p in {#2,...,#3}{%
    \path[shift={(\p,0)}] (0pt,5 pt)--(0pt,-5 pt)
                          node[/LX/.cd,#1,rotate=-30]{\p};}
    \ifnum\Xfrac=1 \node at (0,1){Test frac =1};
    \else \node at (0,1){Test frac =0};
    \fi
}

\begin{document}
\begin{tikzpicture}
    \labelX[frac=1,red,rotate=-30](0,5)
\end{tikzpicture}

\begin{tikzpicture}
    \labelXb[frac=0,blue,draw](0,5)
\end{tikzpicture}

\end{document}

enter image description here

4
  • Since LX doesn't understand rotate it search also TikZ and the transformation becomes rotate -30 which is how much the nodes are rotated.
    – percusse
    May 6, 2016 at 17:32
  • @percusse I agree with your remark but why in the second case the line is horizontal and not in the first May 6, 2016 at 17:34
  • In the second case rotate=-30 only applied to the node but not to the path. In the first one the rotate is set for the current scope to every item since you use \pgfqkeys.
    – percusse
    May 6, 2016 at 17:36
  • It' s not possible to modify the first method to get a line horizontal? With pgf 2.1 and tkz-euclide 1.16 I used something like that and you can see in the doc that I don't have this problem ! May 6, 2016 at 17:44

1 Answer 1

2

In the first case, let's keep track of the transformations: Assume the argument #1 holds only rotate=-30 for simplicity.

\def\labelX[#1](#2,#3){%
\pgfqkeys{/LX}{#1}% Here it is equivalent to \tikzset{rotate=-30}
\foreach \p in {#2,...,#3}{%
     %
     % Here still rotate=-30 is enforced hence the path below obeys the rotation.
     %
     \path[shift = {(\p,0)}] (0pt,5 pt)--(0pt,-5 pt) 
                            node[/LX/.cd,#1]{\p};}
     %
     %We can also see the rotation from something at the origin that won't rotate
     %
     %
     \node[circle,fill,inner sep=2pt] {}
     %
     \ifnum\Xfrac=1 \node[transform shape,draw] at (0,1){Test frac =1};
     \else \node at (0,1){Test frac =0};
     \fi
}

enter image description here

The easiest way is to reset the transformations (or at least only the nontranslational ones)

\documentclass[tikz]{standalone}
\pgfkeys{/LX/.cd,
        frac/.store in              = \Xfrac, %not used
        frac                        = 0,
        /LX/.search also            = {/tikz}, 
}  

\def\labelX[#1](#2,#3){%
\pgfqkeys{/LX}{#1}
\foreach \p in {#2,...,#3}{%
\pgftransformresetnontranslations%                <------------
    \path[shift = {(\p,0)}] (0pt,5 pt)--(0pt,-5 pt) 
                            node[/LX/.cd,#1]{\p};}
    \ifnum\Xfrac=1 \node at (0,1){Test frac =1};
    \else \node at (0,1){Test frac =0};
    \fi
}

\begin{document}
\begin{tikzpicture}
    \labelX[frac=1,red,rotate=-30](0,5)
\end{tikzpicture}
\end{document}
3
  • ok but now I don't understand why I got the good result in the doc of tkz-base page 16 and 17 May 6, 2016 at 20:48
  • @AlainMatthes You are saving the label options in a macro and insert them only into the node as you have done in node[xlabel style,fill = \tkz@fillcolor,cmd@X@option]}tkz@temp{\tkz@Xshowgradresult}; hence it is only valid for the node itself. In your first example on this question you are setting a global transformation by setting the key.
    – percusse
    May 10, 2016 at 10:19
  • I forgot that ! with /LX/.search also = {/tikz}, I can use the styles from Tikz but It's very difficult to manage all the keys. The easiest solution seems to be to use a style like \tikzset{xlabel style/.append style={rotate=-30}} and node[xlabel style,/LX/.cd,#1] May 10, 2016 at 16:04

You must log in to answer this question.

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