How to draw an arrow pointing the middle of another arrow using tikz

Antonio Santoro 07/11/2018. 2 answers, 89 views
tikz-pgf arrows

I need to draw the red arrow in the figure but I'm not able to.

enter image description here

Here's my code

\documentclass[10pt,a4paper]{toptesi}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{tikz}
\usetikzlibrary{shapes, positioning}
\author{Antonio Santoro}
\begin{document}
\begin{tikzpicture}[ball/.style={ellipse, minimum width=3cm, minimum height=1.5cm, draw},>=latex]

\node[ball] (classeA) {classe A};
\node[ball, right=2.5cm of classeA] (classeB) {classe B};
\node[ball, above right=2cm of classeA] (loaderL) {loader L};
\node[rectangle,draw,minimum width=2cm,minimum height=1cm, right=4cm of loaderL] (bytecode) {bytecode};

\draw[-] (bytecode) -- node[above] {caricamento} (loaderL);
\draw[->] (loaderL) -- (classeB);
\draw[->] (loaderL) -- (classeA);
\draw[->] (classeA) -- node[above] {intercetta} (loaderL-classeB);

\end{tikzpicture}


\end{document}

but it gives me errors.

2 Answers


Phelype Oleinik 07/11/2018.

Maybe not the most smart solution, but you can add an empty node to the path between loader L and classe B and then draw the arrow to that node:

enter image description here

\documentclass[10pt,a4paper]{toptesi}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{tikz}
\usetikzlibrary{shapes, positioning}
\author{Antonio Santoro}
\begin{document}

\begin{tikzpicture}[ball/.style={ellipse, minimum width=3cm, minimum height=1.5cm, draw},>=latex]

\node[ball] (classeA) {classe A};
\node[ball, right=2.5cm of classeA] (classeB) {classe B};
\node[ball, above right=2cm of classeA] (loaderL) {loader L};
\node[rectangle,draw,minimum width=2cm,minimum height=1cm, right=4cm of loaderL] (bytecode) {bytecode};

\draw[-] (bytecode) -- node[above] {caricamento} (loaderL);
\draw[->] (loaderL) -- node [midway](LtoB){} (classeB);
\draw[->] (loaderL) -- (classeA);
\draw[->] (classeA) -- node [above,sloped] {intercetta} (LtoB);

\end{tikzpicture}

\end{document}

J Leon V. 07/11/2018.

You can define a node in a path like in the visual tikz manual section 7.9. and then draw an arrow usig that point, in this case named M.

enter image description here

\documentclass[border=10pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes, positioning}
\begin{document}
\begin{tikzpicture}[
    ball/.style={
        ellipse,
        minimum width=3cm,
        minimum height=1.5cm,
        draw
    },
    >=latex
]

\node[ball] (classeA) {classe A};
\node[ball, right=2.5cm of classeA] (classeB) {classe B};
\node[ball, above right=2cm of classeA] (loaderL) {loader L};
\node[rectangle,draw,minimum width=2cm,minimum height=1cm, right=4cm of loaderL] (bytecode) {bytecode};

\draw[-] (bytecode) -- node[above] {caricamento} (loaderL);
\draw[->] (loaderL) -- (classeB) node [sloped,midway](M){}; % Declare node in the middle of the path named M
\draw[->] (loaderL) -- (classeA);
\draw[->,red] (classeA) -- (M.center) node[midway,sloped,above]{\sf Label}; %Draw arrow, and put text in a node, declared in the midle again.

\end{tikzpicture}


\end{document}

Related questions

Hot questions

Language

Popular Tags