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'm trying to draw this but except for the straight lines in this diagram I'm not able to place other things such as square and circle properly. How can I do this? Help much appreciated.

example of what I would like to achieve

EDIT: Since MWE is asked I'll post here my code and update it as and when I get close to the picture above.

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[y=.2cm, x=.7cm,font=\sffamily]
    \draw (0,0) -- coordinate (x axis mid) (10,0);
    \draw (0,0) -- coordinate (y axis mid) (0,30);
\end{tikzpicture}
\end{document}
share|improve this question
2  
Could you post what you have so far? It's always nice for folks to have a starting point :) –  cmhughes Nov 1 '11 at 18:37
1  
It is always best to compose a MWE that illustrates what you have done so far, so that those trying to help don't have to recreate it. –  Peter Grill Nov 1 '11 at 18:39
    
I'd have put that but all I got is just a x and y axis. I could draw circles and squares separately but I'm not sure how to place them. –  Sunil Nov 1 '11 at 18:46
    
Good start. Now add \draw (0,20) circle (5pt) node [left] {$t_2$} to place the circle. –  Peter Grill Nov 1 '11 at 18:57
4  
Is there some specific name for this type of diagram? Because in the current form nobody that wants to create something similar is ever going to find this question, making it relatively useless. The question title would be better as How can I create a <diagramname> diagram using LaTeX?. –  Roelof Spijker Nov 1 '11 at 20:35
show 5 more comments

1 Answer

up vote 7 down vote accepted

You can use the following code. The circles are created using nodes and we draw to and from the nodes, because then the line does not go through it. For the circle in the rectangle we define a new shape so we can just use nodes for that as well. The code looks like this:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\makeatletter
\pgfdeclareshape{rectCircle}{
  \inheritsavedanchors[from=rectangle] % this is nearly a rectangle
  \inheritanchorborder[from=rectangle]
  \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{east}
  \backgroundpath{% this is new
    % store lower left in xa/ya and upper right in xb/yb
    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y

    \pgfmathsetmacro{\temp@x}{\pgf@xa+.5*(\pgf@xb-\pgf@xa)}
    \pgfmathsetmacro{\ttemp@x}{.5*(\pgf@xb-\pgf@xa)}    % construct main path
    \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
    \pgfpathclose
    \pgfpathmoveto{\pgfpoint{\temp@x}{\pgf@ya}}
    \pgfpatharc{270}{-90}{\ttemp@x}
 }
}
\makeatother
\begin{tikzpicture}[font=\sffamily]
    \node [circle, draw, minimum size=2.5mm, inner sep=0pt] (t1) at (3,0) {};
    \node [rectCircle, draw] (t5) at (0,2) {};
    \node [circle, draw, minimum size=2.5mm, inner sep=0pt] (t2) at (0,3) {};
    \node [circle, draw, minimum size=2.5mm, inner sep=0pt] (t4) at (2,2) {};
    \node [rectCircle, draw] (t3) at (2,1) {};
    \coordinate (orig) at (0,0);
  \draw (orig) -- (t1) node [below=2mm] {$t_1$};
  \draw [->] (t1) -- ++(0.5,0);
  \draw (orig) -- (t5) node[left=2mm]{$t_5$} -- (t2) node[left=2mm] {$t_2$};
  \draw [->] (t2) -- ++(0,0.5);
  \draw [dashed] (t5) -- (t4) node[right=2mm] {$t_4$} -- (t3) node[right=2mm] {$t_3$};
  \draw [dashed] (t2) -- ++(3,0) node {$\times$} -- (t1);
\end{tikzpicture}
\end{document}

And the resulting image looks like this:

diagram

The most difficult part is the creation of the new node shape, I suppose. This could probably also be done by using overlay and remember picture and drawing the nodes on top of each other. That would require very precise sizing though and wouldn't scale as easily as creating a new shape. Creating the legend is left as an exercise for the reader, should be relatively straightforward now all of the nodes are available.

share|improve this answer
add comment

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.