3

I want to draw the following diagram :

enter image description here

\documentclass[11pt,twoside,a4paper]{book}
\usepackage[margin=0.45in]{geometry}
\usepackage[all]{xy}


\begin{document}

\begin{figure}[ht]
 \[\xymatrix{&&&&& n+1 \ar[r]^{\sigma} & \dots \ar@{..}[dd]\\
0 \ar[r]_{\sigma} & 1 \ar[r]_{\sigma} & 2 \ar[r]_{\sigma}  \cdots &  n-1     \ar[r]_{\sigma} & n \ar[ru]^{\sigma} & &\\
&&&&&   n+m-1\ar[lu]^{\sigma}  & \ar[l]^{\sigma}\dots 
}\]
\caption{Cyclic State Machine}
\end{figure}

\end{document}    

This produces :
enter image description here

Which is not like I want. How can I draw my desired figure ?

3
  • In what, precisely, the figure you obtain doesn't satisfy you?
    – egreg
    May 31, 2013 at 9:24
  • The arrow between 'n+m-1' and 'n' should start from 'n',the position of sigma at right side of 'n+m-1' should middle on the arrow and finally the whole arrow will be bold. May 31, 2013 at 9:34
  • although it's possible to adjust the positioning of the node text, it's rather tedious and non-obvious how to do so. that isn't the way xy-pic is designed. you might be better off using a different tool. May 31, 2013 at 12:07

2 Answers 2

3

I have solved my problem :

\documentclass[11pt,twoside,a4paper]{book}
 \usepackage[margin=0.45in]{geometry}
\usepackage[all]{xy}


\begin{document}

\begin{figure}[ht]
 \[\xymatrix{&&&&& n+1 \ar[rr]^{\sigma} && \ar@{..}[dd]\\
0 \ar[r]_{\sigma} & 1 \ar[r]_{\sigma} & 2 \ar[r]_{\sigma}  \cdots &  n-1     \ar[r]_{\sigma} & n \ar[ru]^{\sigma} & &\\
&&&&&   **[r]n+m-1\ar[lu]^{\sigma}  & &\ar[l]^{\sigma}
}\]
\caption{Cyclic State Machine}
\end{figure}


\end{document}  

Produces :

enter image description here

2

Here's a TikZ solution.

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[x=1mm,y=1mm]
\node (0) at (0,0) {0};
\node[right=of 0] (1) {1};
\draw[->,>=stealth] (0) -- node[auto, swap] {$\sigma$} (1);
\node[right=of 1] (2) {2};
\draw[->,>=stealth] (1) -- node[auto, swap] {$\sigma$} (2);
\node[right=of 2] (dots) {$\dots$};
\draw[->,>=stealth] (2) -- node[auto, swap] {$\sigma$} (dots);
\node[right=of dots] (predn) {$n-1$};
\draw[->,>=stealth] (dots) -- node[auto, swap] {$\sigma$} (predn);
\node[right=of predn] (n) {$n$};
\draw[->,>=stealth] (predn) -- node[auto, swap] {$\sigma$} (n);
\node[above right=5 of n] (sucn) {$n+1$};
\draw[->,>=stealth] (n) -- node[auto] {$\sigma$} (sucn.south west);
\node[below right=5 of n] (nm) {$n+m-1$};
\draw[<-,>=stealth] (n) -- node[auto, swap] {$\sigma$} (nm.north west);
\node[right=of nm] (offbot) {};
\draw[<-,>=stealth] (nm) -- node[auto, swap] {$\sigma$} (offbot);
\node at (offbot |- sucn) (offtop) {};
\draw[->,>=stealth] (sucn) -- node[auto] {$\sigma$} (offtop);
\draw[dotted,line width=1,shorten <=5, shorten >=5] (offbot) -- (offtop);
\end{tikzpicture}
\end{document}

Some explanatory comments.

  • The positioning library is loaded so that nodes can be positioned relative to each other.

  • The >=stealth key sets the style of the arrow tips.

  • The auto key puts the σ labels a "nice" distance away from the arrows; without this they'd be on top of the arrows.

  • The swap key puts the σ labels on the other side of the arrow, where appropriate.

  • The shorten > and shorten < keys make a given line a bit shorter at both of its ends.

  • The x |- y construction positions a new node at the horizontal position of node x and the vertical position of node y.

  • The things in parentheses like (0),(predn), (nm) etc are just names, for referring to nodes.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .