Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to make a symbol as shown below in TikZ.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
    \draw[thick] (0,0) rectangle (3,1);
    \draw[thick] (0.5,0) -- (0.5,1);
    \draw[thick] (0.5,0.5) -- (3.5,0.5);
    \draw[thick] (0.25,0) -- +(0,-0.3);
    \draw[thick] (2.75,0) -- +(0,-0.3);
\end{tikzpicture}
\end{document}

enter image description here

I need to insert it (say cylinder) in TikZ codes, like so:

\draw[cylinder] (2,2); % this inserts the symbol at point (2,2)
share|improve this question
    
Have you considered making an ordinary macro for this? \newcommand\cylinder[2]{...} then \cylinder{2}{2} –  John Wickerson May 23 '13 at 9:01
2  
It might be worth to define a new shape in this case. Perhaps the makeshape will help you. –  Claudio Fiandrino May 23 '13 at 9:18

1 Answer 1

up vote 2 down vote accepted

As suggested by John Wickerson, you can write the \cylinder macro:

\documentclass{standalone}
\usepackage{tikz}

\newcommand\cylinder[2][]{
  \begin{scope}[shift={(#2)}]
    \draw[#1] (0,0) rectangle (3,1);
    \draw[#1] (0.5,0) -- (0.5,1);
    \draw[#1] (0.5,0.5) -- (3.5,0.5);
    \draw[#1] (0.25,0) -- +(0,-0.3);
    \draw[#1] (2.75,0) -- +(0,-0.3);
  \end{scope}
}

\begin{document}
\begin{tikzpicture}
  \cylinder{0,0}
  \cylinder[draw=blue,very thick]{2,2}
  \coordinate (A) at (4,4);
  \cylinder[draw=red,line width=5pt]{A}
\end{tikzpicture}
\end{document}

Result:

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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