我需要与另一条线相交,如下所示:
我正在考虑使用[near start]并使用节点:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[label=above:A] (A) at (0,1) {$\bullet$};
\node[label=above:B] (B) at (1,0) {$\bullet$};
\node[label=above:C] (C) at (1,1) {$\bullet$};
\draw (A) -- (B) node[near start=1cm, below] {D} node[near start=1cm] {$\bullet$};
\end{tikzpicture}
\end{document}
或者使用坐标,更清晰:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,1);
\draw (A) node[above] {A} node {$\bullet$};
\coordinate (B) at (1,0);
\draw (B) node[above] {B} node {$\bullet$};
\coordinate (C) at (1,1);
\draw (C) node[above] {C} node {$\bullet$};
\draw (A) -- (B) node[near start=1cm, below] {D} node[near start=1cm] {$\bullet$};
\end{tikzpicture}
\end{document}
我已经放置了标签 D,但我不能再使用它来绘制线 (DC)。有人有什么想法吗?
编辑 :[near start] 类似于 [pos=0.25],我认为这是放置节点的更好方法
答案1
C
只需在所需位置放置一个坐标并单独添加项目符号标签。然后连接和的坐标D
:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,1);
\draw (A) node[above] {A} node {$\bullet$};
\coordinate (B) at (1,0);
\draw (B) node[above] {B} node {$\bullet$};
\coordinate (C) at (1,1);
\draw (C) node[above] {C} node {$\bullet$};
\draw (A) -- (B) node[near start=1cm, below] {D} coordinate[near start=1cm] (D);
\node at (D) {$\bullet$};
\draw (D) -- (C);
\end{tikzpicture}
\end{document}
答案2
使用calc
库,您可以控制节点的位置D
,例如,
\coordinate (D) at ($(A)!0.25!(B)$);
然后从C
到绘制D
。
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,1);
\draw (A) node[above] {A} node {$\bullet$};
\coordinate (B) at (1,0);
\draw (B) node[above] {B} node {$\bullet$};
\coordinate (C) at (1,1);
\draw (C) node[above] {C} node {$\bullet$};
\coordinate (D) at ($(A)!0.25!(B)$);
\draw (D) node[below] {D} node {$\bullet$};
\draw (A) -- (B) ;
\draw (C) -- (D);
\end{tikzpicture}
\end{document}
答案3
只是更紧凑的语法
\documentclass[tikz, border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}[%
point/.style={circle, draw, thin, fill=blue, minimum size=2pt, inner sep=0pt},
text=blue, font=\sffamily\scriptsize, label distance=-2pt]
\draw[thick] (0,1) node[point, label=A]{} -- node[near start, point, label=D] (d) {} (1,0) node[point, label=B] {};
\draw[thick] (d) -- (1,1) node[point, label=C]{};
\end{tikzpicture}
\end{document}