我如何才能改善这些 tikz 箭头中的文本换行?

我如何才能改善这些 tikz 箭头中的文本换行?

请考虑下图:

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

渲染结果如下

在此处输入图片描述

我对非弯曲箭头非常满意,但如果文字与箭头一起弯曲,并可以放在箭头的最后三分之一处,那就更好了。如何做到这一点?

答案1

我注释了你的代码行,但没有删除它们,而是在下面放了新代码。如果你需要解释,就说出来,我会更详细地解释。

截屏

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

答案2

这只是一个部分答案,其中的文字用箭头弯曲,因为我无法放置环境\cite{}

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

在此处输入图片描述

相关内容