TikZ 中沿弯曲箭头的文本

TikZ 中沿弯曲箭头的文本

我想在 TikZ 中沿着弯曲的箭头写一些文字。当我不弯曲箭头时,一切都按预期工作,但是当我添加它时,文本的定位变得荒谬。这是一个 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}

输出:

在此处输入图片描述

q_1位置正确,因为箭头没有弯曲,但d_1箭头没有弯曲。有办法解决这个问题吗?或者有什么解决方案可以很好地显示Pool和之间的双重交换x_1

非常感谢。

答案1

我会做这样的事情:

\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}

在此处输入图片描述

答案2

当使用 时tonode必须放在 之后to,而不是 下一个坐标之后,即(a) to node{foo} (b)而不是(a) to (b) node[midway]{foo};

\tikzstyle顺便说一句,我认为 已被弃用。它仍然有效,但推荐的方法是\tikzset{style A/.style={...}, style B/.style={...}}

代码输出

\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}

答案3

  • 您真的需要为边标签命名节点吗?
  • 有必要tikzpicture有选择overlay,remember picture吗?
  • 图像是否必须在figure环境中(我看不到标题)?

如果答案是否定的,那么我宁愿使用以下解决方案:

\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}

在此处输入图片描述

相关内容