TransWikia.com

How can I improve the text wrap in these tikz arrows?

TeX - LaTeX Asked by Pedro Tamaroff on October 4, 2021

Consider the following diagram:

documentclass{article}
usepackage{tikz}

usetikzlibrary{shapes.arrows, positioning}
tikzset{->,>=stealth}

begin{document}

begin{tikzpicture}
        node (A) at (1, 0) {$A$};
        node (P) at (4, -4) {$P$};
        node (C) at (9, -2) {$C$};
        node (Z) at (9, 2) {$Z$};
        node (D) at (4, 4) {$D$};
        node (D') at (-2, 4) {$D'$};
        node (PL) at (-2, -4) {$PL$};
        node (L) at (-7, -2) {$L$};
        node (L') at (-7,2 ) {$L'$};
        draw (A) to (P);
        draw[densely dotted] (L) to node[above,rotate= 13,black]{scriptsize Some text here}(A);
        draw (P) to node[below,rotate= 21,black]{scriptsize Longer comment.}(C);
        draw (C) to node[above,rotate= -90,black]{scriptsize Short comment.}(Z);
        draw[bend left =15, densely dotted] (PL) to node[ above right=of D,rotate=45,black]{scriptsize A useful remark here.}(D);
        draw (D) to (Z);
        draw (A) to (D);
            draw[densely dotted] (A) to node[above,rotate= -13,black]{scriptsize Some more text.}
(C);
        draw[bend right =15, densely dotted] (D') to node[below right=of A,rotate=-45,black]{scriptsize More text here, too}(P);
        draw (PL) to node[below,rotate=52,black]{scriptsize Text here,too.}(A);
        draw (L) to node[below,rotate= -21,black]{scriptsize Some more text.} (PL);
        draw (D') to (A);
        draw (L') to (D');
        draw (L') to node[above,rotate= 90,black]{scriptsize The last bit of text}(L);
end{tikzpicture}

end{document}

Which renders as

enter image description here

I am perfectly happy with the non-curved arrows, but it would be nice if the text curved with the arrows, and could be put in the last third of the arrow. What’s the way to do this?

2 Answers

I commented the lines of your code without deleting them and just underneath, I put the new code. If you need an explanation, just say so, I'll explain more fully.

screenshot

documentclass[border=5mm]{standalone}
usepackage{tikz}

usetikzlibrary{shapes.arrows, positioning}
usetikzlibrary{decorations.text}
tikzset{->,>=stealth}

begin{document}

begin{tikzpicture}
        node (A) at (1, 0) {$A$};
        node (P) at (4, -4) {$P$};
        node (C) at (9, -2) {$C$};
        node (Z) at (9, 2) {$Z$};
        node (D) at (4, 4) {$D$};
        node (D') at (-2, 4) {$D'$};
        node (PL) at (-2, -4) {$PL$};
        node (L) at (-7, -2) {$L$};
        node (L') at (-7,2 ) {$L'$};
        draw (A) to (P);
        draw[densely dotted] (L) to node[above,rotate= 13,black]{scriptsize Some text here}(A);
        draw (P) to node[below,rotate= 21,black]{scriptsize Longer comment.}(C);
        draw (C) to node[above,rotate= -90,black]{scriptsize Short comment.}(Z);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ---- old path ------------------------------------------------------
%        draw[bend left =15, densely dotted] (PL) to node[ above right=of D,rotate=45,black]{scriptsize A useful remark here.}(D);
% ---- new path decorated with the text «A useful remark here» --------
        draw [bend left =15, densely dotted,-latex, postaction={decorate,decoration={raise=3pt,text along path,text align={right,right indent=8mm},text={|scriptsize|A useful remark here}}}] (PL) to  (D);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        draw (D) to (Z);
        draw (A) to (D);
            draw[densely dotted] (A) to node[above,rotate= -13,black]{scriptsize Some more text.}
(C);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ---- old path -------------------------------------------------------
%        draw[blue,bend right =15, densely dotted] (D') to node[below right=of A,rotate=-45,black]{scriptsize More text here, too}(P);
% ---- new path decorated with the text «More text here, too» ----------
        draw [bend right =15, densely dotted,-latex, postaction={decorate,decoration={raise=3pt,text along path,text align={right,right indent=10mm},text={|scriptsize|More text here, too}}}] (D') to  (P);  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%      
        draw (PL) to node[below,rotate=52,black]{scriptsize Text here,too.}(A);

        draw (L) to node[below,rotate= -21,black]{scriptsize Some more text.} (PL);
        draw (D') to (A);
        draw (L') to (D');
        draw (L') to node[above,rotate= 90,black]{scriptsize The last bit of text}(L);
end{tikzpicture}

end{document}

Correct answer by AndréC on October 4, 2021

This is only a partial answer with the text curved with the arrows because I'm not able to put the cite{} environments:

documentclass{article}
usepackage{tikz}
usepackage[margin=2cm]{geometry}
usetikzlibrary{shapes.arrows, positioning}
usetikzlibrary{decorations.text}
tikzset{->,>=stealth}

begin{document}

begin{tikzpicture}
        node (A) at (1, 0) {$A$};
        node (P) at (4, -4) {$P$};
        node (C) at (9, -2) {$C$};
        node (Z) at (9, 2) {$Z$};
        node (D) at (4, 4) {$D$};
        node (D') at (-2, 4) {$D'$};
        node (PL) at (-2, -4) {$PL$};
        node (L) at (-7, -2) {$L$};
        node (L') at (-7,2 ) {$L'$};
        draw (A) to (P);
        draw[densely dotted] (L) to node[above,rotate= 13,black]{scriptsize Some text here}(A);
        draw (P) to node[below,rotate= 21,black]{scriptsize Longer comment.}(C);
        draw (C) to node[above,rotate= -90,black]{scriptsize Short comment.}(Z);
        draw [densely dotted,postaction={decorate,decoration={raise=1ex,text along path,text align=center,text={|scriptsize|A useful remark here.}}}] (PL) to [bend left=45] (D);
        draw (D) to (Z);
        draw (A) to (D);
            draw[densely dotted] (A) to node[above,rotate= -13,black]{scriptsize Some more text.}
(C);
draw [densely dotted,postaction={decorate,decoration={raise=1ex,text along path,text align=center,text={|scriptsize|More text here, too.}}}] (D') to [bend left=345] (P);
        draw (PL) to node[below,rotate=52,black]{scriptsize Text here,too.}(A);
        draw (L) to node[below,rotate= -21,black]{scriptsize Some more text.} (PL);
        draw (D') to (A);
        draw (L') to (D');
        draw (L') to node[above,rotate= 90,black]{scriptsize The last bit of text}(L);
end{tikzpicture}

end{document}

enter image description here

Answered by Sebastiano on October 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP