Tikz:调整箭头的长度

Tikz:调整箭头的长度

所以我试着画出这个路径图

在此处输入图片描述

到目前为止我有以下内容

\documentclass[12pt,a4paper]{article}
\usepackage{tkz-graph}
\usetikzlibrary{positioning,shapes.multipart,calc,arrows.meta}

\tikzset{
  basic/.style={draw, text centered},
  circ/.style={basic, circle, minimum size=2em, inner sep=1.5pt},
  rect/.style={basic, text width=1.5em, text height=1em, text depth=.5em},
  1 up 1 down/.style={basic, text width=1.5em, rectangle split, rectangle split horizontal=false, rectangle split parts=2},
}

\begin{document}

\begin{center}
\begin{tikzpicture}
  \node [rect] (base) {$Y$};
  \node [rect, right=of base] (I) {$I$};
  \node [rect, right=of I] (r) {$r$};
  \node [circ, left=of base] (L) {$L$};
  \node [circ, above=0.4em of L] (K) {$K$};
  \node [circ, above=1em of I] (G) {$G$};
        \draw [->] (K) -- (base);
        \draw [->] (L) -- (base);
        \draw[->] (base) -- (I);
        \draw [->] (I) -- (r);
        \draw [->] (G) -- (I);
\node [rect, above right= 0.1em of base] (C) {$C$};
        \draw [->] (base) -- (C) -- (I);
\node [circ, above left=1em of C] (T) {$T$};];
        \draw [->] (T) -- (C);
\end{tikzpicture} 
\end{center}

\end{document}

这给了我这个

在此处输入图片描述

我的问题是,如何使底部、Y 和 I 之间的箭头的长度更大,以便 C 可以容纳进去?

答案1

你可以这样做:

\documentclass[12pt,a4paper]{article}
\usepackage{tkz-graph}
\usetikzlibrary{positioning,shapes.multipart,calc,arrows.meta}

\tikzset{
  basic/.style={draw, text centered},
  circ/.style={basic, circle, minimum size=2em, inner sep=1.5pt},
  rect/.style={basic, text width=1.5em, text height=1em, text depth=.5em},
  1 up 1 down/.style={basic, text width=1.5em, rectangle split, rectangle split horizontal=false, rectangle split parts=2},
}

\begin{document}

\begin{center}
\begin{tikzpicture}[>=latex]
  \node [rect] (base) {$Y$};
  \node [rect, above right=.2em and 3em of base] (C) {$C$};
  \node [rect, below right=.2em and 3em of C] (I) {$I$};
  \node [rect, right=of I] (r) {$r$};
  \node [circ, left=of base] (L) {$L$};
  \node [circ, above=0.4em of L] (K) {$K$};
  \node [circ, above=1em of I] (G) {$G$};
        \draw [->] (K) -- (base);
        \draw [->] (L) -- (base);
        \draw [->] (base) -- (I);
        \draw [->] (I) -- (r);
        \draw [->] (G) -- (I);
        \draw [->] (base) -- (C);
        \draw [->] (C) -- (I);
\node [circ, above left=.2em and 2em of C] (T) {$T$};
        \draw [->] (T) -- (C);
\end{tikzpicture} 
\end{center}

\end{document}

在此处输入图片描述

Y为了使、C和之间具有对称性I,可以将它们放置如下:

  \node [rect] (base) {$Y$};
  \node [rect, above right=.2em and 3em of base] (C) {$C$};
  \node [rect, below right=.2em and 3em of C] (I) {$I$};

这样就C可以处于Y和之间的中间位置I

另外,为了定位T,你可以写

\node [circ, above left=.2em and 2em of C] (T) {$T$};

来控制它的高度和到左边的距离C

答案2

箭头的长度取决于节点之间的距离。加载positioning包时的默认值为 15 毫米(I 东西),因此如果将其增加到 24 毫米,则将有更多空间在 Y 和 I 之间安装节点 C:

\documentclass[12pt,a4paper]{article}
\usepackage{tkz-graph}
\usetikzlibrary{positioning,shapes.multipart,calc,arrows.meta}

\tikzset{
  basic/.style={draw, text centered},
  circ/.style={basic, circle, minimum size=2em, inner sep=1.5pt},
  rect/.style={basic, text width=1.5em, text height=1em, text depth=.5em},
  1 up 1 down/.style={basic, text width=1.5em, rectangle split, rectangle split horizontal=false, rectangle split parts=2},
}

\begin{document}

\begin{center}
\begin{tikzpicture}[node distance=24mm]
  \node [rect] (base) {$Y$};
  \node [rect, right=of base] (I) {$I$};
  \node [rect, right=of I] (r) {$r$};
  \node [circ, left=of base] (L) {$L$};
  \node [circ, above=0.4em of L] (K) {$K$};
  \node [circ, above=1em of I] (G) {$G$};
        \draw [->] (K) -- (base);
        \draw [->] (L) -- (base);
        \draw[->] (base) -- (I);
        \draw [->] (I) -- (r);
        \draw [->] (G) -- (I);
\node [rect, above right= 5mm of base] (C) {$C$};
        \draw [->] (base) -- (C) -- (I);
\node [circ, above left=1em of C] (T) {$T$};];
        \draw [->] (T) -- (C);
\end{tikzpicture}
\end{center}
    \end{document}

随着距离的增加,node distanve您还需要增加 Y 和 C 之间局部确定的距离(参见代码)。这样,图像就变成:

在此处输入图片描述

如果只想增加 Y 和 I 节点之间的距离,则线

\node [rect, right=of base] (I) {$I$};

例如替换宽度

\node [rect, right=24mm of base] (I) {$I$};

相关内容