Tikz:如何设置节点的精确位置

Tikz:如何设置节点的精确位置

我制作了以下 tikz 图片:

\begin{figure}[h]
\centering
\begin{center}
    \begin{tikzpicture}[->, >=stealth', auto, semithick, node distance=3cm]
    \tikzstyle{every state}=[fill=white,draw=black,thick,text=black,scale=1]
    \node[state]    (A)                     {\textborn};
    \node[state]    (B)[right of=A]   {$\diamond_0$};
    \node[state]    (D)[right of=B]   {$...$};
    \node[state]    (E)[right of=D]   {$\diamond_5$};
    \node[state]    (C)[below of=B]   {\textdied};
    \path
    (A) edge[loop left]         node{$1-i_x-q_x^a$} (A)
    (A) edge[bend right,below]  node{$i_x$} (B)
    (A) edge[bend right,left]   node{$q_{x}^a$} (C)
    (B) edge[bend right,below]  node{$r_{x,x}$} (A)
    (C) edge[loop below,below]          node{$1$}   (C)
    %-------------%
    (B) edge[below]     node{$1-r_{x-1,x}-q_{x-1,x}^i$} (D)
    edge[right]     node{$q_{x,x}^i$}   (C)
    (D) edge[bend right = 40,above]     node{$r_{j,x}$} (A)
    (D) edge[bend left]     node{$q_{x-j,x}^i$} (C)
    %-------------%
    (D) edge[below]     node{$1-r_{x-4,x}-q_{x-4,x}^i$} (E)
    (E) edge[loop right]            node{$1-q_{x}^i-r_{x}$} (E)
    edge[bend left]     node{$q_{x}^i$} (C)
    (E) edge[bend right = 50, above]    node{$r_{x}$} (A);
    %\node[above=0.5cm] (A){Patch G};
    %\draw[red] ($(D)+(-1.5,0)$) ellipse (2cm and 3.5cm)node[yshift=3cm]{Patch H};
    \end{tikzpicture}
\end{center}
\end{figure}

如您所见,从\diamond_0\dots和 从\dots到 的箭头\diamond_5对于文本来说太小了。有人有什么好主意吗,而不必重新定位整个 tikz 图形?谢谢!

答案1

像这样?

在此处输入图片描述

您应该使用positioning带有其语法的库(确定节点之间的距离),减少边缘标签的字体大小(例如\footnotesize),并对边缘标签使用quotes库:

\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, automata,
                calc,
                positioning,
                quotes}


\begin{document}
    \begin{tikzpicture}[
node distance = 2cm and 3cm,
   arr/.style = {-Stealth, semithick},
every edge/.append style = {-Stealth, semithick},
every edge quotes/.style = {auto, font=\footnotesize }
                        ]
   \begin{scope}[nodes=state]
\node               (A) {\textborn};
\node[right=of A]   (B) {$\diamond_0$};
\node[right=of B]   (D) {$\dots$};
\node[right=of D]   (E) {$\diamond_5$};
\node[below=of B]   (C) {\textdied};
    \end{scope}
\path   (A) edge[loop left, "$1-i_x-q_x^a$"]    (A)
        (A) edge[bend right, "$i_x$"]           (B)
        (A) edge[bend right, "$q_{x}^a$"]       (C)
        (B) edge[bend right,"$r_{x,x}$"]        (A)
        (C) edge[loop below,"$1$"]              (C)
%-------------%
        (B) edge["$1-r_{x-1,x}-q_{x-1,x}^i$"]   (D)
           edge["$q_{x,x}^i$"]   (C)
        (D) edge[bend right=40,"$r_{j,x}$"]     (A)
        (D) edge[bend left]     node{$q_{x-j,x}^i$} (C)
%-------------%
        (D) edge["$1-r_{x-4,x}-q_{x-4,x}^i$"]       (E)
        (E) edge[loop right,"$1-q_{x}^i-r_{x}$"]    (E)
            edge[bend left,"$q_{x}^i$"]         (C)
        (E) edge[bend right=50,"$r_{x}$"]       (A);
    
    \end{tikzpicture}
\end{document}

注意:不要使用已弃用的\tikzstyle,而是作为选项tikzpicture或使用\tikzset

相关内容