1

I am looking for a way to put Text (or a symbol similar to N actually) along the arrow, such that it aligns with the arrow. Currently i am manually aligning it, which is a pain for large figures. Following is a representative example with "strike through" which works well. Thanks

\documentclass[border=1pt]{standalone}
\def\xcolorversion{2.00}
\def\xkeyvalversion{1.8}

\usepackage[version=0.96]{pgf}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{arrows,shapes,snakes,automata,backgrounds,petri}
\usetikzlibrary{shapes.misc}
\usetikzlibrary{decorations,decorations.markings,patterns}
\usepackage[latin1]{inputenc}
\colorlet{darkgray}{black!60}

\tikzset{
  place/.style={
  circle,
  draw=black,
  fill=white,
  inner sep=0pt,
  minimum size=6mm,
  font=\sffamily\scriptsize,
 },
 strike through/.style={
  postaction=decorate,
  decoration={
  markings,
  mark=at position #1 with {
    \draw[-] (-2pt,-2pt) -- (2pt, 2pt);
        }
    }
   }
 }

\begin{document}
\begin{tikzpicture}[node distance=1.3cm,>=stealth',bend angle=45,auto, ->, every node/.style={font=\sffamily\large}]

\begin{scope}
  %P
  \path
  (0,0)  node (Start) [place, tokens=0, label=above:{\footnotesize Start}] {}
  (2,-2)  node (Stop) [place, tokens=0, label=below:{\footnotesize Stop}] {}
  ;
  \path[every node/.style={font=\sffamily\tiny}]
  (Stop) edge [right, pos=0.5, strike through=0.5]  node[above] {\footnotesize $3$} (Start)
  (Start) edge [bend right]  node[midway,above=-0.7em, rotate=-30] {N} (Stop)
  ;
\end{scope}

\end{tikzpicture}
\end{document}

enter image description here

1
  • You could use anchor=center. Like this:\path[every node/.style={font=\sffamily\tiny}] (Stop) edge [right, pos=0.5, strike through=0.5] node[above] {\footnotesize $3$} (Start) (Start) edge [bend right] node[midway,anchor=center, rotate=-30] {N} (Stop) ;
    – Bobyandbob
    Commented Dec 13, 2017 at 19:33

2 Answers 2

2

You can use the argument sloped for a node anywhere on the arrow. I also replaced the strike through with the symbol$\not$ (there are other alternatives as well).

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
  >=stealth,
  font=\sffamily,
  node distance=2cm,
  place/.style={
    circle,
    draw=black,
    fill=white,
    inner sep=0pt,
    minimum size=6mm},
  ]
  \path
  (0,0)  node (Start) [place, label=above:{\footnotesize Start}] {}
  (2,-2)  node (Stop) [place, label=below:{\footnotesize Stop}] {}
  ;
  \path
  (Stop) edge[->]  node[pos=0.5,sloped]{$\not$}  node[pos=0.5,anchor=-135,inner sep=1pt] {\footnotesize $3$} (Start)
  (Start) edge [->,bend right=45]  node[pos=0.5,sloped,font=\sffamily\tiny] {N} (Stop)
  ;
\end{tikzpicture}
\end{document}

enter image description here

1

For fun, an easy way to do this with pstricks:

\documentclass[border=20pt, svgnames]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pst-node}
%\usepackage{auto-pst-pdf} % To compile with pdflatex -shell-escape (TeX Live, MacTeX)%{ mnode = C,
                                                         % pdflatex --enable-write18 (MiKTeX)

\begin{document}

\psset{radius = 0.4cm, linejoin = 1, arrowinset=0.12, arrows =->, shortput = nab, fillstyle = solid, fillcolor = WhiteSmoke, linecolor = SlateGray, labelsep = 3pt}
\sffamily\footnotesize
\begin{psmatrix}[colsep=3cm, rowsep = 2cm]
\Cnode{St}\nput{90}{St}{Start}\\
& \Cnode{Sp}\nput{90}{Sp}{Sto\smash{p}}
% %%% labels and arrows
\psset{linecolor = black}
\ncline{Sp}{St}\nbput[npos = 0.54, labelsep = 0pt]{3}\ncput{\psline[arrows = -, linewidth = 0.5pt](-0.1,0)(0.1,0)}
\ncarc[arcangle =-45, fillstyle = none, fillcolor]{St}{Sp}\ncput*[nrot =-45, fillcolor = white, framesep = 1.5pt]{N}
\end{psmatrix}

\end{document} 

enter image description here

You must log in to answer this question.

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