# Define a pic and use it as node

My purpose is draw an horizontal cylinder. I defined the left and the right base with /.pic . Now I would link these bases with \draw, using the bases anchor point .north and .south. Something goes wrong: no output

\documentclass[12pt]{article}

\usepackage{tikz}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\tikzset{
leftbase/.pic={
code={
\draw (-\xR,0) arc(90:270:0.5cm and 1cm);
\draw (-\xR,0) arc(90:-90:0.5cm and 1cm);
}
},
rightbase/.pic={
code={
\draw[dotted] (-\xR+1.7in,0) arc(90:270:0.5cm and 1cm);
\draw         (-\xR+1.7in,0) arc(90:-90:0.5cm and 1cm);
}
}
}
node[leftbase] (lb) {};
node[rightbase] (rb) {};
\end{tikzpicture}
\end{figure}
\end{document}


Any idea?

• Will it change, when you draw the nodes which represent the pics? Jul 30, 2022 at 14:35
• Yes, it change with \pic{leftbase} and \pic{rightbase} Jul 30, 2022 at 14:46
• Drawing the pics? Jul 30, 2022 at 15:07
• i.imgur.com/16bZFXa.jpg Jul 30, 2022 at 15:23
• Jul 30, 2022 at 15:47

Maybe you're not using pic correctly. Here a slight change that makes your code work:

\documentclass[12pt]{article}

\usepackage{tikz}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\tikzset{
leftbase/.pic={
code={
\draw (-\xR,0) arc(90:270:0.5cm and 1cm);
\draw (-\xR,0) arc(90:-90:0.5cm and 1cm);
}
},
rightbase/.pic={
code={