0

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={
\def\xR{0.5cm}; %x radius of ellipse \def\yR{1cm}; %y radius of ellipse
\draw (-\xR,0) arc(90:270:0.5cm and 1cm); \draw (-\xR,0) arc(90:-90:0.5cm and 1cm); } }, rightbase/.pic={ code={
\def\xR{0.5cm}; %x radius of ellipse \def\yR{1cm}; %y radius of ellipse
\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?

user3713179
  • 635
  • 2
  • 11

1 Answers1

5

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

pic as a node (quite)

\documentclass[12pt]{article}

\usepackage{tikz}

\begin{document} \begin{figure} \centering \begin{tikzpicture} \tikzset{ leftbase/.pic={ code={
\def\xR{0.5cm}; %x radius of ellipse \def\yR{1cm}; %y radius of ellipse
\draw (-\xR,0) arc(90:270:0.5cm and 1cm); \draw (-\xR,0) arc(90:-90:0.5cm and 1cm); } }, rightbase/.pic={ code={
\def\xR{0.5cm}; %x radius of ellipse \def\yR{1cm}; %y radius of ellipse
\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); } } } \pic [local bounding box=lb] at (0,0) {leftbase}; \pic [local bounding box=rb] at (1,0) {rightbase}; \draw (lb.north) -- (rb.north); \draw (lb.south) -- (rb.south);
\end{tikzpicture} \end{figure} \end{document}

SebGlav
  • 19,186