我想画出如下图所示不同角度倾斜的来回箭头(不是双向箭头)。图中不必显示的灰色点用于定位。
\documentclass[UTF8,fontset=windows]{ctexart}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{calc,positioning}
\newcommand\lrreturn[3][]{%left right
\draw[->,#1]($(#2.0)+(0,2pt)$)--($(#3.180)+(0,2pt)$);
\draw[<-,#1]($(#2.0)+(0,-2pt)$)--($(#3.180)+(0,-2pt)$);
}
\newcommand\udreturn[3][]{%up down
\draw[->,#1]($(#2.-90)+(2pt,0)$)--($(#3.90)+(2pt,0)$);
\draw[<-,#1]($(#2.-90)+(-2pt,0)$)--($(#3.90)+(-2pt,0)$);
}
\begin{document}
\tikz[node distance=1.5em and 2em,line width=1pt,>=latex]{
\node[red,font=\bfseries] (a) {Center};
\node[right=of a,blue] (b) {0};
\node[below=of a,blue] (c) {$-\pi/2$};
\lrreturn[red]ab
\udreturn[red]ac
}
\tikz{
\node[draw] (o) at (0,0) {Center};
\foreach \i in {0,30,...,180} {
\node[draw] (x\i) at (\i:2) {\i};
\draw[latex-latex] (o) to (x\i);
}}
\end{document}
答案1
如果未绘制节点(或节点为圆形),则此解决方案有效。此外,它仅适用于直线。
用法是\draw[twoway] (A) to (B);
在坐标(A)和(B)之间绘制来回箭头。
基本上,计算垂直于给定线的向量,然后使用与pathreplacing
原始线的短垂直距离绘制两个箭头。箭头之间的距离由 全局控制\arsp
。
\documentclass[UTF8,fontset=windows]{ctexart}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{calc,positioning,decorations.pathreplacing}
\newcommand{\arsp}{.8mm}
\tikzset{
twoway/.style={
decoration={
show path construction,
lineto code={
\path (\tikzinputsegmentfirst); \pgfgetlastxy{\a}{\b};
\path (\tikzinputsegmentlast); \pgfgetlastxy{\x}{\y};
\coordinate (uu) at ($(0,0)!.5*\arsp!(\b-\y,\x-\a)$);
\draw[-latex]($(\a,\b)+(uu)$) to ($(\x,\y)+(uu)$);
\draw[latex-]($(\a,\b)-(uu)$) to ($(\x,\y)-(uu)$);
}
}, decorate
}
}
\begin{document}
\tikz{
\node[draw,circle] (o) at (0,0) {Center};
\foreach \i in {0,30,...,180} {
\node[draw,circle] (x\i) at (\i:2) {\i};
\draw[twoway] (o) to (x\i);
}}
\end{document}