考虑以下(灵感来自这个帖子):
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (1,1);
\draw [->, red] (a) -| (b);
\draw [->] (a).. controls (a -| b) .. (b); % Shorter way to do this?
\end{tikzpicture}
\end{document}
它给:
有没有更短、更弯曲的方法来获得第二种路径?
答案1
不清楚你说的“更弯曲”是什么意思。像这样吗?
编辑(1): 考虑了@Paul Gaborit 的评论:
编辑(2):arrows.meta
添加了和库 的使用bending
:
绘制第二条线作为线curved corners=<radius>
:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
bending}
\tikzset{> = {Straight Barb[bend]},
}
\begin{document}\small
With default radius value:
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (1,1);
\draw [->, red] (a) -| (b);
\draw [->, rounded corners] (a) -| (b);
\end{tikzpicture}
With radius of 10mm:
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (1,1);
\draw [->, red] (a) -| (b);
\draw [->, rounded corners=10mm] (a) -| (b);
\end{tikzpicture}
\end{document}
答案2
不确定问题中的“更短路径”具体指什么,但我发现如果曲线由out=0
和 指定,in=-90
并且looseness=
用于控制如何曲线美你想要它。
以下是 的三种不同设置的示例looseness=
:
代码:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (1,1);
\draw [->, red] (a) -| (b);
%\draw [->] (a).. controls (a -| b) .. (b); % Shorter way to do this?
\draw [black, ->] (a) to[out=0, in=-90, looseness=1.50] (b);
\draw [orange,->] (a) to[out=0, in=-90, looseness=1.25] (b);
\draw [blue, ->] (a) to[out=0, in=-90, looseness=0.75] (b);
\end{tikzpicture}
\end{document}