6

I'm using tikzpicture and I have some graphs, but I want some graphs with arrows. Is there any simple syntax change for that?

My Graph:

\begin{tikzpicture}[thick]
         \begin{scope}
           \draw (4,0) node[label=below:5] {};
...
         \end{scope}
         \draw 
...
         (4,4) -- (6,0);
\end{tikzpicture}
  • Hi Bene, welcome to TeX.sx. You can mark code by selecting it and pressing the {} button. I've edited your question accordingly. I've also removed the greeting from the beginning of your question, which is just the style used on this site.` – Jake Nov 8 '11 at 12:03
  • 3
    If I understand you correctly change \draw to \draw [->] or \draw [<-]. There are also more arrow heads available. See the PGF/TikZ manual. – Martin Scharrer Nov 8 '11 at 12:03
8

As Martin commented you can use [->] in the \draw command to add an arrow. Different arrow style can also be specified by using options such as: -stealth, -latex, etc.. Here are a few types:

enter image description here

See Section 23 Arrow Tip Library for a list of the various ones that are already available. Adding \usepgflibrary{arrows} to your preamble provides a large variety of built in arrows.

\documentclass[border=3pt]{standalone}
\usepackage{tikz}
\usepgflibrary{arrows}% for more options on arrows

\begin{document}
\begin{tikzpicture}[thick]
\draw [green, ->          ] (0,8.0) -- (1,8.0);
\draw [blue,  -stealth    ] (0,7.5) -- (1,7.5) node [right] {stealth};
\draw [red,   -latex      ] (0,7.0) -- (1,7.0) node [right] {latex};
\draw [cyan,  -to         ] (0,6.5) -- (1,6.5) node [right] {to};
\draw [brown, -triangle 60] (0,6.0) -- (1,6.0) node [right] {triangle 60};
\end{tikzpicture}
\end{document}

Since you included a scope in your example, it should be noted that you can also specify the arrow to be used for each line in a scope as well by adding that to the options to \begin{scope}. In the following all lines will have -stealth arrows. Adding - will disable the arrow for a particular line:

enter image description here

\documentclass[border=3pt]{standalone}
\usepackage{tikz}
\usepgflibrary{arrows}% for more options on arrows

\begin{document}
\begin{tikzpicture}[thick]
\begin{scope}[-stealth]
    \draw [blue   ] (0,7.5) -- (1,7.5) node [right] {stealth};;
    \draw [red,   ] (0,7.0) -- (1,7.0) node [right] {stealth};
    \draw [brown,-] (0,6.5) -- (1,6.5);
\end{scope}
\end{tikzpicture}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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