# Shape missing using pic in TikZ

Why the shape (sB) is unknown in the following code ? How to avoid this ?

\documentclass[]{standalone}
\usepackage{tikz,xparse}
\usetikzlibrary{calc}

\tikzset{pics/.cd,
% Marque croix
Cross/.style args={#1 and #2}{%
code = {%
\draw[#2,rotate=45,scale=1.4] (0,#1 pt) -- (0,-#1 pt) ;
\draw[#2,rotate=-45,scale=1.4] (0,#1 pt) -- (0,-#1 pt) ;
}
},
Cross/.default={2 and black}
}

\NewDocumentCommand{\Segment}{mO{}}{%
\begin{scope}[#2]
\path    (0,0) coordinate (sA) pic {Cross={1.5 and gray}}
-- (#1,0) coordinate (sB) pic {Cross={1.5 and gray}} ;
\draw (sA)--(sB) ; % Can't reuse (sB)
\end{scope}
}

\begin{document}
\begin{tikzpicture}
\Segment{1.5}
\end{tikzpicture}
\end{document}

• For your second question on avoiding: \path (0,0) coordinate (sA) pic {Cross={1.5 and gray}}; \path (#1,0) coordinate (sB) pic {Cross={1.5 and gray}} ; in the definition of \Segment – user11232 Nov 11 '14 at 7:55
• @HarishKumar is not possible to use two or more pics on same path? – Ignasi Nov 11 '14 at 8:00
• @Ignasi Why not? Try \draw (0,0) -- pic[pos=0] {Cross={1.5 and gray}} pic[pos=1] {Cross={1.5 and gray}} (#1,0); for example. – user11232 Nov 11 '14 at 8:05
• @HarishKumar Mixing your to remarks, on can do :  \draw (0,0) coordinate (sA) -- (#3,0) coordinate (sB) \foreach \i in {0,1} {pic[pos=\i] {Cross={1.5 and gray}}};  – Tarass Nov 11 '14 at 8:14
• @HarishKumar OK, forget my question. Mark solved it. – Ignasi Nov 11 '14 at 8:23

This appears to be a bug. The internal command \iftikz@node@is@pic is not reset after a pic on a path so any subsequent nodes (coordinates are nodes) are parsed as pics and consequently nothing is done.
\def\tikz@do@after@node{\tikz@node@is@picfalse\tikz@scan@next@command}

• There is another workaround to this bug that I have seen somwehre on TeX.SX (the author was @percusse I think), we can isolate the pic in a group like this {pic[..]{..}}. For exemple in OP we can do \path (0,0) coordinate (sA) {pic{Cross={1.5 and gray}}} -- (#1,0) coordinate (sB) pic{Cross={1.5 and gray}};. – Kpym Jan 14 '15 at 13:13