Search code examples
latextikz

How do I fix this tag positioning issue on TikZ?


I'm using Tikz to illustrate an idea. But I can't seem to align the tags as I would want. The code I'm using is this:

\usepackage[spanish]{babel}
\decimalpoint
\usepackage{fancyhdr} % Required for custom headers
\usepackage{lastpage} % Required to determine the last page for the footer
\usepackage{extramarks} % Required for headers and footers
\usepackage[usenames,dvipsnames]{color} % Required for custom colors
\usepackage{graphicx} % Required to insert images
\usepackage{listings} % Required for insertion of code
\usepackage{courier} % Required for the courier font
\usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{natbib}
\usepackage{enumitem}
\usepackage{tikz}
\usetikzlibrary{babel}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}

    \node (o) at (0,0) {};
    \node (n1) at (2.1,1.1) {};
    \node (n2) at (8.9,3.9) {};
    \node (a1) at (2.1,0.3) {};
    \node (a2) at (8.9,4.9) {};
    \node (p1) at (2.1,0.1) {};
    \node (p2) at (8.9,4.9) {};

    \draw[->] (2,0) -- (9,0)            node[at end, sloped, below] {$z$};
    \draw[->] (2,0) -- (2,5)            node[at end,left]           {$u(z)$};
    \draw (n1) -- (n2)                  node[midway, sloped, above] {Neutralidad};
    \draw (a1) to [bend left=30] (a2)   node[near end, sloped]      {Propensión};
    \draw (p1) to [bend right=35] (p2)  node[midway, sloped]        {Aversión};

    \end{tikzpicture}

    \end{document}

But the tags when I use the bend option appear one on top of the other and not in the position I want, they appear at the bottom left of the graph. Does anyone know how to fix this?


Solution

  • The node needs to be before the second coordinate:

    \documentclass{article}
    
    \usepackage[spanish]{babel}
    \decimalpoint
    \usepackage{fancyhdr} % Required for custom headers
    \usepackage{lastpage} % Required to determine the last page for the footer
    \usepackage{extramarks} % Required for headers and footers
    \usepackage[usenames,dvipsnames]{color} % Required for custom colors
    \usepackage{graphicx} % Required to insert images
    \usepackage{listings} % Required for insertion of code
    \usepackage{courier} % Required for the courier font
    \usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template
    \usepackage{amsmath}
    \usepackage{amssymb}
    \usepackage{natbib}
    \usepackage{enumitem}
    \usepackage{tikz}
    \usetikzlibrary{babel}
    \usetikzlibrary{positioning}
    
    \begin{document}
    \begin{tikzpicture}
    
        \node (o) at (0,0) {};
        \node (n1) at (2.1,1.1) {};
        \node (n2) at (8.9,3.9) {};
        \node (a1) at (2.1,0.3) {};
        \node (a2) at (8.9,4.9) {};
        \node (p1) at (2.1,0.1) {};
        \node (p2) at (8.9,4.9) {};
    
        \draw[->] (2,0) -- (9,0)            node[at end, sloped, below] {$z$};
        \draw[->] (2,0) -- (2,5)            node[at end,left]           {$u(z)$};
        \draw (n1) -- (n2)                  node[midway, sloped, above] {Neutralidad};
        \draw (a1) to [bend left=30]    node[near end, sloped, above]      {Propensión} (a2);
        \draw (p1) to [bend right=35]   node[midway, sloped,above]        {Aversión}  (p2);
    
        \end{tikzpicture}
    
        \end{document}
    

    enter image description here