3

On the picture below (generated with TikZ library), I would like to put AA above its arrow, and BB below its arrow:

enter image description here

Here is my code so far:

\begin{figure}
    \centering
    \begin{tikzpicture}[thick, node distance=9em and 15em, every node/.style={align=center}]
    
    % Nodes
    \node[block, drop shadow=black, fill=lightgray] (space) {Search Space};
    \node[block, drop shadow=black, fill=lightgray, right of=space, xshift=1cm] (strategy) {Search Strategy};
    \node[block, drop shadow=black, fill=lightgray, right of=strategy,xshift=3cm] (performance){Performance \\Estimation Strategy};
    

    % Arrows
    \path[-latex] (space) edge node[fill=white, anchor=center, inner sep=2pt] {a} (strategy);
    \path[-latex] (strategy) edge[bend left=0.5cm] node[fill=white, anchor=center, yshift=-0.1cm] {AA} (performance);
    
     \path[-latex] (performance) edge[bend left=0.5cm] node[fill=white, anchor=center, yshift=0.1cm] {BB} (strategy);

    \end{tikzpicture}
    \caption{Graph-based structure of the behaviours}
    \label{fig:nas-def}
\end{figure}

I could not find anywhere how to do this, any idea ?

7
  • Have you tried anchor=north for BB and anchor=south for AA instead of anchor=center?
    – Markus G.
    Commented May 28, 2021 at 19:02
  • @MarkusG. Hello, anchor value is for the location of the tip of the arrow, center means that the arrow will point at the center of the segment
    – mricdev
    Commented May 28, 2021 at 19:08
  • Not all of them. The text a node along the arrow, so it should work. However, I cannot test it right now.
    – Markus G.
    Commented May 28, 2021 at 19:17
  • But where do you put "anchor=north" ? tell me I will try :)
    – mricdev
    Commented May 28, 2021 at 19:33
  • In the node options just before the text, the ones that begin with fill=white
    – Markus G.
    Commented May 28, 2021 at 19:35

2 Answers 2

1

If you want to place nodes above, just put above in its declaration.

above and below

\documentclass[tikz,border=3.14mm]{standalone}

\usetikzlibrary{shadows,shapes,positioning}
\tikzset{block/.style={draw,minimum height=1cm, drop shadow=black, fill=lightgray}}

\begin{document}
    \begin{tikzpicture}[thick, node distance=2cm]
    
    \node[block] (space) {Search Space};
    \node[block, right = of space] (strategy) {Search Strategy};
    \node[block, right = of strategy, text width=3.5cm,align=center] (performance){Performance \\ Estimation Strategy};
    
    \draw[-latex] (space) -- (strategy) node[fill=white,inner sep=2pt,midway] {a};
    \draw[-latex] ([yshift=5pt]strategy.east) to[bend left] node[above,midway] {AA} ([yshift=5pt]performance.west) ;
    \draw[-latex] ([yshift=-5pt]performance.west) to[bend left] node[below,midway] {BB} ([yshift=-5pt]strategy.east) ;

    \end{tikzpicture}
\end{document}
0

After examining your figure, I found some more points that in my opinion needed optimisation. Here is my take on it:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shadows,shapes,positioning}
\begin{document}
    \begin{tikzpicture}[
        node distance=2cm,
        block/.style={rectangle, drop shadow=black, fill=lightgray,align=center},
        arrow/.style={thick,->,>=latex}]
    
    % Nodes
    \node[block] (space) {Search Space};
    \node[block, right =of space] (strategy) {Search Strategy};
    \node[block, right =of strategy, text width=3.5cm,align=center] (performance){Performance \\ Estimation Strategy};
    
    % Arrows
    \draw[arrow] (space) -- (strategy) node[anchor=south,inner sep=2pt,midway] {a};
    \draw[arrow] (strategy.5) -- (performance.170) node[anchor=south,midway,sloped] {AA};
    \draw[arrow] (performance.190) -- (strategy.355) node[anchor=north, midway,sloped] {BB} ;

    \end{tikzpicture}
\end{document}

which results in this:

enter image description here

EDIT: Or if you insist on the bent-arrows:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shadows,shapes,positioning}
\begin{document}
    \begin{tikzpicture}[
        node distance=2cm,
        block/.style={rectangle, drop shadow=black, fill=lightgray,align=center},
        arrow/.style={thick,->,>=latex}]
        
        % Nodes
        \node[block] (space) {Search Space};
        \node[block, right =of space] (strategy) {Search\\ Strategy};
        \node[block, right =of strategy,text width=3.5cm] (performance){Performance \\ Estimation Strategy};
        
        % Arrows
        \draw[arrow] (space) -- (strategy) node[anchor=south,inner sep=2pt,midway] {a};
        \draw[arrow] (strategy.north east) to[out=60,in=130] node[anchor=south,midway] {AA} (performance.north west);
        \draw[arrow] (performance.south west) to[out=240,in=300] node[anchor=north, midway] {BB} (strategy.south east);
    \end{tikzpicture}
\end{document}

Which looks like this: enter image description here

You must log in to answer this question.

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