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.

Two things:

1) How do I make the semicircle portion of my shape have the same thickness as the straight lines?

2) How do I fill the overall shape with a filling gray colour?

Here is my code so far:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[scale=0.5]
\draw (10,0.4) arc (90:270:0.4cm);
\draw (10,0.4) -- (12,0.4);
\draw (10,-0.4) -- (12,-0.4);
\draw (12,0.4) arc (90:-90:0.4cm);
\end{tikzpicture}
\end{document}
share|improve this question
    
The thickness looks the same. So it might depend on the viewer. –  stalking is prohibited Aug 25 at 19:56

3 Answers 3

up vote 3 down vote accepted

It is a combination of broken path joins and viewer rendering quality. You can draw it at one shot or put a node instead.

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[blue,fill=blue!30] (0,0.4) arc (90:270:0.4cm)-- (2,-0.4) arc (-90:90:0.4cm)--cycle;
\node[draw=red,fill=red!30,rounded corners=0.4cm,minimum height=0.8cm,minimum width=2.8cm,inner sep=0mm,transform shape] at (1,1) {};
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Thanks, thats exactly what I wanted, +1 –  Jack Aug 25 at 20:22

A solution with PSTricks just for fun.

\documentclass[pstricks,border=12pt]{standalone}
\begin{document}
\begin{pspicture}(10,4)
    \pscustom[dimen=m,fillstyle=solid,fillcolor=orange,linewidth=2pt]
    {
        \psarc(2,2){2}{90}{-90}
        \psarc(8,2){2}{-90}{90}
        \closepath
    }
\end{pspicture}
\end{document}

enter image description here

share|improve this answer
    
+1 for the effort, thanks. –  Jack Aug 25 at 20:23

Just for comparison, in Metapost you can either draw the path directly using halfcircles or use the rboxes library to make rounded boxes.

enter image description here

prologues:=3;outputtemplate:="%j%c.eps";

% A macro that returns the path of a rectangle with rounded ends
vardef vessel(expr width, height) = 
   halfcircle rotated -90 scaled height shifted (+1/2 width,0) --
   halfcircle rotated +90 scaled height shifted (-1/2 width,0) --
   cycle
   enddef;

% for the alternative approach
input rboxes;

beginfig(1);

   % draw the shape centred at the origin
   draw vessel(40,20);

   % in order to fill, draw and label the shapes, you can save them as path variables
   path a,b; 

   a = vessel(55,21) shifted 30 up;
   fill a withcolor .4 blue + .6 white;
   draw a withcolor .8 blue;
   label(btex Vessel $V_1$ etex, center a);

   b = vessel(55,21) shifted 55 up;
   fill b withcolor .4 red + .6 white;
   draw b withcolor .8 red;
   label(btex Vessel $V_2$ etex, center b);

   % or you might prefer the "rboxes" approach
   rboxit.c(btex Vessel $V_3$ etex);
   c.dx = 18; c.dy = 5;
   c.s = 70 up; 
   fill bpath.c withcolor .85 white;
   drawboxed(c);

endfig;
end
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.