Hi tush,
here is a quick way with the
quotes
library syntax:
Code: Select all
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{quotes}
\tikzset{every edge quotes/.style =
{ fill = white,
sloped,
execute at begin node = $,
execute at end node = $ }}
\begin{document}
\begin{tikzpicture}
\draw[<->] (0,0) to ["l_1 = 2 m"] (6,0) ;
\draw[<->] (0,0) to ["l_2 = 1 m"] (0,3) ;
\end{tikzpicture}
\end{document}
Commonly metric units are written in upright shape, to distinguish from (italic) variables. There's the
siunitx package that does proper unit typesetting, I use it here:
Code: Select all
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{quotes}
\usepackage{siunitx}
\tikzset{every edge quotes/.style =
{ fill = white,
sloped,
execute at begin node = $,
execute at end node = $ }}
\begin{document}
\begin{tikzpicture}
\draw[<->] (0,0) to ["l_1 = \SI{2}{m}"] (6,0) ;
\draw[<->] (0,0) to ["l_2 = \SI{1}{m}"] (0,3) ;
\end{tikzpicture}
\end{document}
Click on "Run LaTeX here" to see the output.
Stefan