6

I want to write some text along bent arrows in TikZ. When I don't bend the arrow everything works as expected, but when I add it, the positioning of the text becomes absurd. Here is a MWE:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}

\begin{frame}{}
  \tikzstyle{leaf}=[shape=circle,draw=black,fill=green!20,minimum size=0.01cm]
  \tikzstyle{pool}=[shape=rectangle,draw=black,fill=blue!20,minimum width=4cm,minimum height=1cm]
  \begin{figure}[t]
    \begin{tikzpicture}[overlay,remember picture]
      \node[pool] (biomass_pool) at (0,-2) {Pool};
      \node[leaf] (leaf_1) at (-5.5,1.5) {$x_1$};
      \draw [{Latex[length=1.5mm]}-] (leaf_1) -- (biomass_pool) node [pos=.5, above, sloped] (TextNode1) {$q_1$};
      \draw [-{Latex[length=1.5mm]},dotted] (leaf_1) to [bend left=5]  (biomass_pool) node [pos=.5, below, sloped] (TextNode2) {$d_1$};
    \end{tikzpicture}
  \end{figure}
\end{frame}

\end{document}

and the output:

enter image description here

q_1 is correctly placed since the arrow is not bent, but d_1 isn't. Is there a way to fix this? Or any solution to display nicely this double exchange between Pool and x_1?

Many thanks.

8

I would do something like this:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}

    \begin{frame}{}
    \tikzstyle{leaf}=[shape=circle,draw=black,fill=green!20,minimum size=0.01cm]
    \tikzstyle{pool}=[shape=rectangle,draw=black,fill=blue!20,minimum width=4cm,minimum height=1cm]
    \begin{figure}[t]
        \begin{tikzpicture}[overlay,remember picture]
        \node[pool] (biomass_pool) at (0,-2) {Pool};
        \node[leaf] (leaf_1) at (-5.5,1.5) {$x_1$};
        \draw [{Latex[length=1.5mm]}-] (leaf_1) to [bend right=30] node [above, sloped] (TextNode1) {$q_1$} (biomass_pool);
        \draw [-{Latex[length=1.5mm]},dotted] (leaf_1) to [bend left=30]  node [above, sloped]  (TextNode2) {$d_1$} (biomass_pool);
        \end{tikzpicture}
    \end{figure}
\end{frame}

\end{document}

enter image description here

8

When using to, the node has to be placed right after to, not after the next coordinate, i.e. (a) to node{foo} (b) instead of (a) to (b) node[midway]{foo};.

\tikzstyle is I believe considered deprecated by the way. It still works, but the recommended method is \tikzset{style A/.style={...}, style B/.style={...}}.

output of code

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}

\begin{frame}{}
  \tikzset{
      leaf/.style={shape=circle,draw=black,fill=green!20,minimum size=0.01cm},
      pool/.style={shape=rectangle,draw=black,fill=blue!20,minimum width=4cm,minimum height=1cm}
  }
  \begin{figure}[t]
    \begin{tikzpicture}[overlay,remember picture]
      \node[pool] (biomass_pool) at (0,-2) {Pool};
      \node[leaf] (leaf_1) at (-5.5,1.5) {$x_1$};
      \draw [{Latex[length=1.5mm]}-] (leaf_1) -- (biomass_pool) node [pos=.5, above, sloped] (TextNode1) {$q_1$};
      \draw [-{Latex[length=1.5mm]},dotted] (leaf_1) to[bend left=5] node [below, sloped] (TextNode2) {$d_1$} (biomass_pool);
    \end{tikzpicture}
  \end{figure}
\end{frame}

\end{document}
2
  • do you really need named nodes for edge labels?
  • is it necessary that tikzpicture has options overlay,remember picture?
  • is necessary that the image is in figure environment (i don't see caption)?

if answers are no, than i would rather use the following solution:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, quotes}

\begin{document}

\begin{frame}
\frametitle{My image}
\centering
    \begin{tikzpicture}[%overlay,remember picture, % do you really need this?
%
    auto,
    leaf/.style={circle,draw,fill=green!20,minimum size=1mm},
    pool/.style={draw,fill=blue!20,minimum width=4cm,minimum height=1cm},
     Arr/.style={-{Latex[length=1.5mm]}},
                        ]
    \node[pool] (biomass_pool)  at (0,-2) {Pool};
    \node[leaf] (leaf_1)        at (-5.5,1.5) {$x_1$};
    \draw[Arr] (biomass_pool)   to [bend left=30,"$q_1$"] (leaf_1);
    \draw[Arr,dotted] (leaf_1)  to [bend left=30,"$d_1$"]   (biomass_pool);
    \end{tikzpicture}
\end{frame}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.