4

My code and the result are follows:

\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}

enter image description here

I want to put two labels on my each vector. The first one is Di (say D1, D2, etc. as seen in my figure), second one is end of the extend, such as E1, E2, E3 and En. How can I achieve this?

4

node [midway] {$D_{\i}$} is really node [pos=0.5] {$D_{\i}$} which places the node half way along. It's maybe not the optimal method when shorten= takes a length but the same method can be used for the labels at the end. The pos= key functions as might be expected for values outside of 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}

enter image description here

5

Dai Bowen's answer is easier and more convenient, this is just to show an alternative method using the syntax of the calc library.

\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}

enter image description here

  • 1
    Probably the better method given shorten expects a length and pos a ratio. \node at ($(P)!-1cm!(q\i)$) {$E_\i$}; works with \draw [-latex, shorten >= -0.7500cm](q\i)--(P) just as well as \draw [-latex](q\i)--($(P)!-0.75cm!(q\i)$) if use of the shorten option is preferred. – Dai Bowen Feb 20 '17 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.