TikZ 箭头提示不匹配

TikZ 箭头提示不匹配

我正在尝试在 TikZ 中连接两条线,并使用一个实心圆来表示连接。这是我的代码:

\tikzset{
block/.style = {draw, fill=white, shape border rotate=270, regular polygon, regular polygon sides=3, minimum height=0.5em, minimum width=0.5em},
int/.style = {draw, fill=white, rectangle, minimum height=0.5em, minimum width=0.5em}
}

\begin{tikzpicture}[auto, node distance=0.75cm,>=latex']
\node [int] (int) {$\frac{1}{s}$};

\draw [draw,->] (int.east) -- ++(0: 2cm);
\draw [draw,*->] (int.east)++(0 :1cm) -- ++(90 :1cm);

\end{tikzpicture}

它产生以下内容:

为什么这两条线不匹配?我怎样才能让它们匹配?

谢谢

答案1

箭头(线开头的点也是箭头)会延长线的长度。因此,您的代码的结果是可以预期的。要解决您的问题,您有两种可能性:

  • 用黑色圆圈将线拉长
  • 在连接坐标中绘制此圆

在第一种情况下,您可以尝试:

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows}

\tikzset{
block/.style = {draw, fill=white, shape border rotate=270, regular polygon, regular polygon sides=3, minimum height=0.5em, minimum width=0.5em},
int/.style = {draw, fill=white, rectangle, minimum height=0.5em, minimum width=0.5em}
}

\begin{document}
\begin{tikzpicture}[auto, node distance=0.75cm,>=latex']
\node [int] (int) {$\frac{1}{s}$};
\draw [draw,->] (int.east) -- ++(0: 2cm);
\draw [draw,*->,shorten <=-2.2pt] (int.east)++(0 :1cm) -- ++(90 :1cm);
\end{tikzpicture}
    \end{document}

在第二种情况下,将图像代码更改为:

\begin{tikzpicture}[auto, node distance=0.75cm,>=latex']
\node [int] (int) {$\frac{1}{s}$};
\draw [draw,->] (int.east) -- ++(0: 2cm);
\draw [draw,->,fill=black] (int.east)++(0 :1cm) -- ++(90 :1cm);
\draw [fill=black] (int.east)++(0 :1cm) circle (2.2pt);
\end{tikzpicture}

在这两种情况下,你都会获得相同的结果:

在此处输入图片描述

答案2

你可以用装饰来做!顺便说一句,\draw [draw]这是多余的,因为绘制命令已经包含在第一个命令中。

输出

在此处输入图片描述

代码

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}

\usetikzlibrary{decorations.markings, arrows.meta}

\tikzset{
    block/.style = {draw, fill=white, shape border rotate=270, regular polygon, regular polygon sides=3, minimum height=0.5em, minimum width=0.5em},
    int/.style = {draw, fill=white, rectangle, minimum height=0.5em, minimum width=0.5em},
    mjoin/.style={decoration={
        markings,
        mark=at position 0 with {\node[circle,fill, inner sep=1pt] {};}},postaction={decorate}}
}
\begin{document}
\begin{tikzpicture}[auto, node distance=0.75cm, -{Latex}]
\node [int] (int) {$\frac{1}{s}$};

\draw (int.east) -- ++(0: 2cm);
\draw [mjoin] (int.east)++(0 :1cm) -- ++(90 :1cm);

\end{tikzpicture}
\end{document}

答案3

圆设置为箭头尖端。因此尖端(而不是圆尖端的中间)与起点对齐。

以下答案使用库arrows.meta,因为它允许配置圆的大小。然后知道半径并据此延长线:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{arrows.meta}
\begin{document}
\tikzset{
  int/.style={
    draw,
    fill=white,
    rectangle,
    minimum height=0.5em,
    minimum width=0.5em,
  },
}
\newdimen\joincircleradius
\setlength{\joincircleradius}{4pt}

\begin{tikzpicture}[auto, node distance=0.75cm,>=latex']
\node [int] (int) {$\frac{1}{s}$};

\draw [->] (int.east) -- ++(0: 3cm);
\draw [*->] (int.east)++(0 :1cm) -- ++(90 :1cm);
\draw [
    {Circle[length=\the\joincircleradius]}->,
    shorten <=-.5\joincircleradius,
] (int.east) ++(0: 2cm) -- ++(90: 1cm);

\end{tikzpicture}
\end{document}

结果

相关内容