[Tex/LaTex] label \psline and orient label in the direction of the arrow

arrowspstricks

How can I label the \psline entity with a label that is positioned/oriented (not placed horizontally taking too much space) on the line itself?

MWE:

\documentclass{standalone}

\usepackage{pstricks-add, pst-plot}
\usepackage{auto-pst-pdf}
\usepackage{xcolor}
\setlength\parindent{0pt}
\pagestyle{empty}

\begin{document}

\begin{pspicture}(0,0)(18,18)
\psset{linecolor=DodgerBlue4, tickcolor=white, subtickcolor=DodgerBlue4, gridcolor=DodgerBlue4, gridlabelcolor=white}%
\psset{linewidth=0.05pt, tickwidth=0.05pt, ticksize=-2pt 2pt, subticks=2, subtickwidth=0.025pt, labels=none}
\psframe[linewidth=0.05pt](0,0)(18,18)
\psset{gridwidth=0.05pt, subgriddiv=1}
\psgrid(0,0)(18,18)

% insert circles
\pscircle[fillstyle=solid,opacity=0.2, linewidth=0.1](9,9){8}
\pscircle[fillstyle=solid,fillcolor=white,opacity=0.2, linewidth=0.1](9,9){4}
\pscircle[fillstyle=solid,fillcolor=white,opacity=0.2, linewidth=0.1](12,8){4}
\pscircle[fillstyle=solid,fillcolor=lightgray,opacity=0.2, linewidth=0.1](9,6){4}

% insert arrows
\psline[arrows=->,linewidth=2.5pt,linestyle=solid, linecolor=red](9,9) (12,8)
\psline[arrows=->,linewidth=2.5pt,linestyle=solid, linecolor=magenta]{->}(9,9) (9,6)
\psline[arrows=->,linewidth=2.5pt,linestyle=solid, linecolor=blue]{->}(12,8) (9,6)
\psline[arrows=->,linewidth=2.5pt,linestyle=solid, linecolor=blue]{->}(9,9) (6.5,7)

\end{pspicture}
\end{document}

1

Best Answer

You can either add invisible \pclines or work with \pclines instead of \pslines. I illustrate a few possibilities below. (Now with DodgerBlue4, big thanks to @Bernad!)

\documentclass[x11names]{standalone}

\usepackage{pstricks-add, pst-plot}
\usepackage{auto-pst-pdf}
\usepackage{xcolor}
%\definecolor{DodgerBlue4}{RGB}{3,3,192}
\setlength\parindent{0pt}
\pagestyle{empty}

\begin{document}

\begin{pspicture}(0,0)(18,18)
\psset{linecolor=DodgerBlue4, tickcolor=white, subtickcolor=DodgerBlue4, gridcolor=DodgerBlue4, gridlabelcolor=white}%
\psset{linewidth=0.05pt, tickwidth=0.05pt, ticksize=-2pt 2pt, subticks=2, subtickwidth=0.025pt, labels=none}
\psframe[linewidth=0.05pt](0,0)(18,18)
\psset{gridwidth=0.05pt, subgriddiv=1}
\psgrid(0,0)(18,18)

% insert circles
\pscircle[fillstyle=solid,opacity=0.2, linewidth=0.1](9,9){8}
\pscircle[fillstyle=solid,fillcolor=white,opacity=0.2, linewidth=0.1](9,9){4}
\pscircle[fillstyle=solid,fillcolor=white,opacity=0.2, linewidth=0.1](12,8){4}
\pscircle[fillstyle=solid,fillcolor=lightgray,opacity=0.2, linewidth=0.1](9,6){4}

% insert arrows
% method 1: insert an invisible \pcline
\psline[arrows=->,linewidth=2.5pt,linestyle=solid, linecolor=red](9,9) (12,8)
\pcline[linestyle=none](9,9)(12,8)\aput{:U}{label 1}
% method 2: shorter: use \pcline instead of \psline
% note, however, that you need to remove the spaces between the coordinates then
\pcline[arrows=->,linewidth=2.5pt,linestyle=solid, linecolor=magenta]{->}(9,9)(9,6)
\aput{:U}{label 2}
\pcline[arrows=->,linewidth=2.5pt,linestyle=solid, linecolor=blue]{->}(12,8)(9,6)
\Aput{label 3}
\pcline[arrows=->,linewidth=2.5pt,linestyle=solid, linecolor=blue]{->}(9,9)(6.5,7)
\bput{:U}{label 4}
\end{pspicture}
\end{document}

enter image description here