Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

insert label in between a arrow (not below/above) with edge node, tikz

I am trying to draw a graph with an arrow and I would like the label of the arrow to be in between the line (not above or below) like this: how the output should look like : enter image description here

I'm using the tikz library and edge node to draw the arrow between two nodes. Here it is a minimal example with the label above the arrow:

\documentclass[12pt]{article}
\usepackage[letterpaper, margin=1in, top=2.5cm, bottom=2.5cm]{geometry}
\usepackage{xcolor}
\definecolor{corn}{rgb}{0.98, 0.93, 0.36}
\definecolor{emerald}{rgb}{0.31, 0.78, 0.47}

\usepackage{array}
\usepackage{tikz}
\usepackage{siunitx}
\usepackage{float}
\usepackage{subcaption,caption}
\captionsetup{labelsep=period}
\usetikzlibrary{positioning,patterns,arrows,decorations.markings,decorations.pathreplacing,shapes,shapes.misc}
\tikzset{
    %Define standard arrow tip
    >=stealth',
        % Define arrow style
    pil/.style={
           ->,
           thick,
           shorten <=3pt,
           shorten >=3pt,}
}

\title{ }
\begin{document}
\maketitle

\begin{figure}[h!] 
\centering
\caption{}
\label{paths}
\begin{subfigure}{0.9\textwidth}
\resizebox{.9\textwidth}{!}{
\begin{tikzpicture}[shorten >=2pt,on grid,auto]
\node (A) [draw=black,fill=emerald,double=white,double distance=2pt,shape=rounded rectangle,minimum width=4cm ]{A}; 
\node[right=9cm of A] (B) [draw,fill=corn,shape=rounded rectangle,minimum width=4cm ]{B};
\path[->]
    (A) edge[line width=0.742mm] node[ anchor=center, above, pos=0.5,font=\bfseries] {\Huge +} (B);
    \end{tikzpicture}
}
\caption{}
\label{M1w}
\end{subfigure}
\end{figure}

\end{document}%\grid

I've searched online and could not find any example with edge node. I would really appreciate it any help!

like image 228
michela Avatar asked May 30 '17 13:05

michela


1 Answers

Changing the \path as follows seems to do the trick:

\path[->] (A) edge[line width=0.742mm] node[ fill=white, anchor=center, pos=0.5,font=\bfseries] {\Huge +} (B);
like image 110
NickD Avatar answered Sep 21 '22 02:09

NickD