I find the horizontal spacing of the chemarrows in mathematical formulas surprisingly bad. It may well be that the spacing is adjusted to the use in chemistry. If you want an arrow with (approximately) the same length and spacing as a \longrightarrow
, then you can use this code:
\documentclass{article}
\usepackage{amsmath,xspace}
\usepackage{chemarrow}
\newcommand{\lra}{\ensuremath{\mathrel{%
\mkern1.5mu\textrm{\arro\symbol{71}}%
\mkern-1.1mu\textrm{\arro\symbol{65}}%
}}\xspace}
\begin{document}
Test \lra Result
Test $\longrightarrow$ Result
\end{document}
The xspace
package is only needed for having \lra
behave in the same way as $\lra$
(otherwise TeX wouldn't put a space after \lra
). It is always a good idea to include an \xspace
if you use \ensuremath
in a macro that takes no arguments.
For this application, you can just define a new combined arrowhead using \pgfarrowsdeclarecombine{name left}{name right}{outer element left}{outer element right}{inner element left}{inner element right}
:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,decorations.markings}
\begin{document}
\pgfarrowsdeclarecombine{|<}{>|}{|}{|}{latex}{latex}
\def\Dimline[#1][#2][#3]{
%\node at (0,0) {"test: #1 - #2 ..."};
\begin{scope}[>=latex] % redef arrow for dimension lines
\draw[|<->|,
decoration={markings, % switch on markings
mark=at position .5 with {\node[gray] at (0,0.25) {\tiny{#3}};},
},
postaction=decorate] #1 -- #2 ;
\end{scope}
}
\begin{tikzpicture}
\node at (0,0) (nA) {A};
\node at (3,0) (nB) {B};
\Dimline[($(nA)+(0,1)$)][($(nB)+(0,1)$)]['test'] ;
\end{tikzpicture}
\end{document}
Or, in order to be able to scale the arrow tips at will, here's your approach with the decorations. The latex
tips are combined with "empty arrows" to fix the protrusion over the end of the line:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,decorations.markings}
\begin{document}
\pgfarrowsdeclarecombine{dimarrow}{dimarrow}{latex}{latex}{}{}
\def\Dimline[#1][#2][#3]{
\draw[|-|,
decoration={markings, % switch on markings
mark=at position 0 with {\arrowreversed[scale=0.5]{dimarrow}};,
mark=at position .5 with {\node[gray] at (0,0.25) {\tiny{#3}};},
mark=at position 1 with {\arrow[scale=0.5]{dimarrow}};,
},
postaction=decorate] #1 -- #2 ;
}
\begin{tikzpicture}
\node at (0,0) (nA) {A};
\node at (3,0) (nB) {B};
\Dimline[($(nA)+(0,1)$)][($(nB)+(0,1)$)]['test'] ;
\end{tikzpicture}
\end{document}
Best Answer
There are several packages supporting extensible arrows:
amsmath (
\xleftarrow
etc., new commands could be similarly created)extarrows
extpfeil
mathtools
An example suitable for your formula, also demonstrating the optional argument for text under the arrows:
Output: