我想画一个这样的箭头<---d--->
,沿着一条从 x 到 y 的线。谢谢。
答案1
marmot 的回答是:
\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[->] (0,0.5) -- (2,0.5);
\draw[latex-latex] (0,0) -- ++ (2,0) node[midway,fill=white]{label};
\end{tikzpicture}
\end{document}
但我粗略地将其扩展为用于参数化的命令:
\usetikzlibrary{calc}
...
\newcommand{\doublearrowlabel}[5]{
% accepts a start point, end point, spacing, gradient and label
\path let \p1=#1 in coordinate (start) at ({\x1 + #3* cos(#4)},{\y1-#3 * sin(#4)});
\path let \p2=#2 in coordinate (end) at ({\x2 + #3* cos(#4)},{\y2-#3 * sin(#4)});
\draw[latex-latex] (start) -- (end) node[midway,fill=white]{#5};
}
...
\draw [->](-0.5,0.8) -- (1,1);
\doublearrowlabel{(-0.5, 0.8)}{(1, 1)}{-5}{75}{First}
\draw [->](-0.5,0.2) -- (-0.8,0.6);
\doublearrowlabel{(-0.5, 0.2)}{(-0.8, 0.6)}{5}{0}{Second}
\draw [->](0.0,-0.3) -- (0.6, 0.3);
\doublearrowlabel{(0.0,-0.3)}{(0.6, 0.3)}{5}{45}{Third}
\draw [->] (0.6, -0.3) -- (0.0,-0.6);
\doublearrowlabel{(0.6, -0.3)}{(0.0,-0.6)}{5}{65}{Fourth}
答案2
只需数学模式您可以使用简单的代码:
\documentclass[a4paper,12pt]{article}
\usepackage{mathtools}
\begin{document}
$\longleftarrow \mathrm{label}\longrightarrow $
\end{document}
例如,也可以使用 tikz-arrows 包tikz-cd
,您可以获得所需的输出。
\documentclass[a4paper,12pt]{article}
\usepackage{mathtools}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}[column sep=2cm]
{} \arrow[r, "\text{label}" description, leftrightarrow] & {}
\end{tikzcd}
\begin{tikzcd}[row sep=2cm]
{} \arrow[d, "\text{label}" description, leftrightarrow]\\
{}
\end{tikzcd}
\begin{tikzcd}[row sep=2cm, column sep=2cm]
{} & \\
& {} \arrow[lu, "\text{label}" description, leftrightarrow]
\end{tikzcd}
\end{document}