4

I have the following code snippet. In that i define the node (B) with the coordinate operation. Unfortunately i can't access the node later on. LuaLatex exits with the error message:

Package pgf Error: No shape named B is known.

\documentclass{standalone}

\usepackage{tikz}

\usetikzlibrary{calc}

\begin{document}

    \begin{tikzpicture}[>=latex]

        \tikzset{%
            auto/.pic={%
                \draw[fill=black!20] (0,10pt)
                    node[fill=black!20,anchor=south,
                            draw,rectangle,
                            minimum width=3cm,
                            minimum height=0.75cm] (-A) {};

                \draw[fill=black]
                    ($(-A.south west)!0.2!(-A.south east)$) circle (10pt);
                \draw[fill=black] 
                    ($(-A.south west)!0.8!(-A.south east)$) circle (10pt);
            }
        }

        % define node (B)
        \draw[rotate=30,every node/.style={rotate=30}] 
            (0,0) coordinate (A) -- 
            (4,0) pic (Auto) {auto} -- 
            (8,0) coordinate (B);

        \draw[->, line width=1pt] 
            (Auto-A.center) -- +(0,-2) node[midway,right]{$\vec F$};

        % can't access (B)
        \draw (A) -- (B);

    \end{tikzpicture}

\end{document}
  • 2
    Keep the pic inside braces; {pic (Auto) {auto}}. It turns on the picture syntax but doesn't turn off so braces limit the scope. – percusse Feb 18 '14 at 21:53
4

Use a pair of braces around the Auto pic:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

    \begin{tikzpicture}[>=latex,]

        \tikzset{%
            auto/.pic={%
                \draw[fill=black!20] (0,10pt)
                    node[fill=black!20,anchor=south,
                            draw,rectangle,
                            minimum width=3cm,
                            minimum height=0.75cm] (-A) {};
                \draw[fill=black]
                    ($(-A.south west)!0.2!(-A.south east)$) circle (10pt);
                \draw[fill=black] 
                    ($(-A.south west)!0.8!(-A.south east)$) circle (10pt);
            }
        }

        % define node (B)
        \draw[rotate=30,every node/.style={rotate=30}] 
            (0,0) coordinate (A) -- 
            (4,0) {pic (Auto) {auto}} -- 
            (8,0) coordinate (B);

        \draw[->, line width=1pt] 
            (Auto-A.center) -- +(0,-2) node[midway,right]{$\vec F$};

        % can access (B)
        \draw (A) -- (B);

    \end{tikzpicture}

\end{document}

enter image description here

  • 1
    Ok we need a photo finish for this :) – percusse Feb 18 '14 at 21:54
  • 1
    @percusse Indeed! :) – Gonzalo Medina Feb 18 '14 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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