我可以画双线,也可以用某些箭头画圆头。但是,组合起来后它们看起来并不像你期望的那样:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,scopes}
\begin{document}
\begin{tikzpicture}
\draw [line width = 4pt,-round cap] (0,0) -- (0,1);
{ [every path/.style = {double distance = 2pt, very thick}]
\draw (1,0) -- (1,1);
\draw [-round cap] (2,0) -- (2,1);
}
\end{tikzpicture}
\end{document}
我更喜欢双线上的“圆帽”,以使线条在末端弯曲并相交,如下所示:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,scopes}
\begin{document}
\begin{tikzpicture} [very thick, x=1em]
\draw (0,0) -- (0,1)
arc [x radius = 0.5em, y radius = 0.5em, start angle = 180, end angle = 0]
(1,0) -- (1,1);
\end{tikzpicture}
\end{document}
显然我能画出这样的东西,但是我怎样才能用箭头来画呢?
答案1
您可以使用line cap=round
选项(其他允许的值为butt
(默认)和rect
):
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[double distance = 0.5cm,line cap=round] (0,0) -- (1,0);
\end{tikzpicture}
\end{document}
但请注意,帽子超出了实际线的范围(即(0,0)位于帽子的中心而不是边界上)。
以下是实际的箭头:
\documentclass{article}
\usepackage{tikz}
\makeatletter
\pgfarrowsdeclare{open cap}{open cap}
{\pgfarrowsleftextend{+0pt}\pgfarrowsrightextend{+0.5\pgflinewidth}}
{
\pgfmathsetlength{\pgfutil@tempdimb}{.5*\pgflinewidth-.5*\pgfinnerlinewidth}%
\pgfsetlinewidth{\pgfutil@tempdimb}
\pgfsetbuttcap
\pgfsetdash{}{0pt}
\pgfmathsetlength{\pgfutil@tempdima}{.5*\pgfutil@tempdimb+.5*\pgfinnerlinewidth}%
\pgfpathmoveto{\pgfqpoint{0pt}{\pgfutil@tempdima}}
\pgfpatharc{270}{90}{-\pgfutil@tempdima}
\pgfusepathqstroke
}
\makeatother
\begin{document}
\begin{tikzpicture}
\draw[very thick,double distance = 0.5cm,open cap-open cap] (0,0) -- (1,0);
\end{tikzpicture}
\end{document}
这里 (0,0) 位于线的末端(即帽子的边界)。