[Tex/LaTex] Adding symbols at the end(s) of a horizontal line

arrowssymbols

I'm looking for variations of the symbol \relbar, or any other horizontal line that is about as along as a standard-length arrow.

In particular, I'd like to be able to add arrowheads, as in \leftarrow, \rightarrow, \leftrightarrow.

I also wish to be able to add vertical bars, as in \leftfootline from the MnSymbol package.

Symbols for all of the above exist, but the problem is being able to add them in any combination. For instance, a rightarrow with a vertical bar on the right hand side. This yields 16 possible symbols in total.

Ideas, anyone?

Best Answer

One can use TikZ; this is a prototype with a perhaps convenient syntax where the argument to \erelbar consists of two digits (0, 1, 2, or 3):

  • 0 stands for no arrowhead
  • 1 stands for a normal arrowhead
  • 2 stands for a bar
  • 3 stands for both bar and arrowhead

The first digit refers to the left side, the second one to the right side.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}

\makeatletter
\newcommand\@erelb@r[1]{%
  \mathrel{\tikz[baseline=-.5ex]\draw[#1] (0,0)--(0.3,0);}
}
% 0 is for nothing
% 1 is for arrowhead
% 2 is for bar
% 3 is for both
\newcommand{\erelbar}[1]{\@erelbar#1}
\def\@erelbar#1#2{%
  \ifcase\numexpr#1*4+#2\relax
    \@erelb@r{-}\or     % 00
    \@erelb@r{->}\or    % 01
    \@erelb@r{-|}\or    % 02
    \@erelb@r{->|}\or   % 03
    \@erelb@r{<-}\or    % 10
    \@erelb@r{<->}\or   % 11
    \@erelb@r{<-|}\or   % 12
    \@erelb@r{<->}\or   % 13
    \@erelb@r{|-}\or    % 20
    \@erelb@r{|->}\or   % 21
    \@erelb@r{|-|}\or   % 22
    \@erelb@r{|<->|}\or % 23
    \@erelb@r{|<-}\or   % 30
    \@erelb@r{|<->}\or  % 31
    \@erelb@r{|<-|}\or  % 32
    \@erelb@r{|<->|}    % 33
  \else
    \@wrong
  \fi
}
\makeatother
\begin{document}

$a\erelbar{11}b$

$\begin{array}{cccc}
\erelbar{00} & \erelbar{10} & \erelbar{20} & \erelbar{30} \\
\erelbar{01} & \erelbar{11} & \erelbar{21} & \erelbar{31} \\
\erelbar{02} & \erelbar{12} & \erelbar{22} & \erelbar{32} \\
\erelbar{03} & \erelbar{13} & \erelbar{23} & \erelbar{33} \\
\end{array}$
\end{document}

enter image description here

Related Question