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 have something like this:

\SetVertexNormal[Shape     = circle,
                 LineWidth = 2pt]
\SetUpEdge[lw    = 1.5pt,
           color = blue]
...
\begin{tikzpicture}
  \Vertex[x=0 ,y=0]{1}
  \Vertex[x=0 ,y=2]{2}
  \tikzset{EdgeStyle/.append style = {straight}}
  \tikzset{EdgeStyle/.style={->}}
  \Edge(1)(2)
\end{tikzpicture}

This creates a simple directed graph with two nodes (1 and 2) connected by a blue arrow. However, I would like to move the arrow to the center of the line (instead of leaving it at the tip) and would like to change its color to red. Can anyone help me out?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

I assume you're using TikZ and tkz-graph

You can use the decoration.markings library to set a marking at the middle position.
To the human eye this does not look like the middle, though, because only the tip of the arrow is halfway between (1) and (2).
But you can use arbitrary TikZ code in the with {<code goes here>} part. I cloned the first solution and changed it so that it does draw a zero length arrow (without a line). To me it looks better than the first solution.

Code

\documentclass{article}
\usepackage{tikz,tkz-graph}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.markings}
\begin{document}
\SetVertexNormal[
        Shape = circle,
    LineWidth = 2pt
]
\SetUpEdge[
       lw = 1.5pt,
    color = blue
]

\begin{tikzpicture}
    \Vertex[x=0 ,y=0]{1}
    \Vertex[x=0 ,y=2]{2}
    \tikzset{EdgeStyle/.append style = {straight}}
    \tikzset{
        EdgeStyle/.style={
            postaction=decorate,
            decoration={
                markings,
                mark=at position .5 with {\arrow{>}}
            }
        }
    }
    \Edge(1)(2)
    \Vertex[x=0 ,y=0]{1}
    \Vertex[x=0 ,y=2]{2}

    \Vertex[x=1 ,y=0]{1}
    \Vertex[x=1 ,y=2]{2}
    \tikzset{
        EdgeStyle/.style={
            postaction=decorate,
            decoration={
                markings,
                mark=at position .5 with {\draw[red,->] (0,0) (0,0);}
            }
        }
    }
    \Edge(1)(2)
    \Vertex[x=1 ,y=0]{1}
    \Vertex[x=1 ,y=2]{2}
\end{tikzpicture}
\end{document}

Output

Compiled example

Closer look

closer look at the arrow


More solutions can be found: TikZ: How to draw an arrow in the middle of the line?

share|improve this answer
    
Thank you very much –  arshajii Sep 29 '12 at 18:38
    
Oh and one more thing if you wouldn't mind: is there anyway to use a solid triangle for the red arrow tip in the center? –  arshajii Sep 29 '12 at 18:38
    
@A.R.S. Take a look at the PGF/TikZ manual (cmd: texdoc --view pgfmanual), specially the chapter "Arrow Tip Library". You are probably looking for triangle 60. –  Qrrbrbirlbel Sep 29 '12 at 18:41
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.