我的代码和结果如下:
\documentclass[12pt,a4paper]{article}
\usepackage{pgf,tikz,tkz-euclide,pgfplots}
\usepackage{listings,float,amsmath,amssymb,amsfonts,amsthm}
\usetikzlibrary{calc,patterns,angles,quotes,patterns,arrows}
\usetikzlibrary{decorations.pathmorphing,intersections,through,backgrounds,fit,arrows.meta}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\begin{document}
\begin{tikzpicture}[scale=0.95]\tiny
\coordinate (O) at (0,0);
\draw [-latex,very thick] (-1,0)--(6,0)coordinate(X) node[right]{$x$};
\draw [-latex,very thick] (0,-1)--(0,5)coordinate(Y) node[left]{$y$};
\node at (O) [below left]{$O$};
\fill (1,1)coordinate (q1) circle (2pt)node[left]{$q_1$};
\fill (2,3)coordinate (q2) circle (2pt)node[left]{$q_2$};
\fill (3,4)coordinate (q3) circle (2pt)node[left]{$q_3$};
\fill (5,3.5)coordinate (qn) circle (2pt)node[left]{$q_n$};
\fill (4,1.25)coordinate (P) circle (2pt)node[above=1.5mm, right=1mm]{$P$};
\draw [shorten >=0.4cm,shorten <=0.4cm,dotted,thick] (q3) to [bend left=6](qn);
\foreach \i in {1,2,3,n}{
\draw [-latex, shorten >= -0.7500cm](q\i)--(P)node[midway,sloped,above]{$\mathbf{D}_{\i}$};}
\end{tikzpicture}
\end{document}
我想在每个向量上放置两个标签。第一个是 Di(如我的图中所示,例如 D1、D2 等),第二个是延伸的末端,例如 E1、E2、E3 和 En。我该如何实现?
答案1
node [midway] {$D_{\i}$}
实际上是node [pos=0.5] {$D_{\i}$}
将节点放置在中间。当shorten=
需要长度时,这可能不是最佳方法,但对于末尾的标签可以使用相同的方法。pos=
对于 之外的值,键的功能可能与预期一样0-1
。
\documentclass[12pt,a4paper]{article}
\usepackage{pgf,tikz,tkz-euclide,pgfplots}
\usepackage{listings,float,amsmath,amssymb,amsfonts,amsthm}
\usetikzlibrary{calc,patterns,angles,quotes,patterns,arrows}
\usetikzlibrary{decorations.pathmorphing,intersections,through,backgrounds,fit,arrows.meta}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\begin{document}
\begin{tikzpicture}[scale=0.95]\tiny
\coordinate (O) at (0,0);
\draw [-latex,very thick] (-1,0)--(6,0)coordinate(X) node[right]{$x$};
\draw [-latex,very thick] (0,-1)--(0,5)coordinate(Y) node[left]{$y$};
\node at (O) [below left]{$O$};
\fill (1,1)coordinate (q1) circle (2pt)node[left]{$q_1$};
\fill (2,3)coordinate (q2) circle (2pt)node[left]{$q_2$};
\fill (3,4)coordinate (q3) circle (2pt)node[left]{$q_3$};
\fill (5,3.5)coordinate (qn) circle (2pt)node[left]{$q_n$};
\fill (4,1.25)coordinate (P) circle (2pt)node[above=1.5mm, right=1mm]{$P$};
\draw [shorten >=0.4cm,shorten <=0.4cm,dotted,thick] (q3) to [bend left=6](qn);
\foreach \i in {1,2,3,n}{
\draw [-latex, shorten >= -0.7500cm](q\i)--(P)node[midway,sloped,above]{$\mathbf{D}_{\i}$} node [pos=1.375] {$E_{\i}$};}
\end{tikzpicture}
\end{document}
答案2
戴博文的回答比较简单方便,这只是展示一种使用calc
库的语法的替代方法。
\documentclass[12pt,border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[scale=0.95]\tiny
\coordinate (O) at (0,0);
\draw [-latex,very thick] (-1,0)--(6,0)coordinate(X) node[right]{$x$};
\draw [-latex,very thick] (0,-1)--(0,5)coordinate(Y) node[left]{$y$};
\node at (O) [below left]{$O$};
\fill (1,1)coordinate (q1) circle (2pt)node[left]{$q_1$};
\fill (2,3)coordinate (q2) circle (2pt)node[left]{$q_2$};
\fill (3,4)coordinate (q3) circle (2pt)node[left]{$q_3$};
\fill (5,3.5)coordinate (qn) circle (2pt)node[left]{$q_n$};
\fill (4,1.25)coordinate (P) circle (2pt)node[above=1.5mm, right=1mm]{$P$};
\draw [shorten >=0.4cm,shorten <=0.4cm,dotted,thick] (q3) to [bend left=6](qn);
\foreach \i in {1,2,3,n}{
\draw [-latex](q\i)--($(P)!-0.75cm!(q\i)$)
node[midway,sloped,above]{$\mathbf{D}_{\i}$};
\node at ($(P)!-1cm!(q\i)$) {$E_\i$};
}
\end{tikzpicture}
\end{document}