6

I want to mark a variable I with a short vertical or horizontal bar in order to relate it to something being vertical or horizontal in real life. For the vertical line, $I^\shortmid$ (from amssymb) is looking very nicely, but I can't produce a horizontal line of equal length. I tried $I^{\rotatebox[origin=c]{90}{$\shortmid$}}$, however this makes the bar longer for reasons I don't understand:

unequally long bars

Taking a different symbol like I^- and I^\text{-} produces ugly results as well. Can someone please explain what is happening inside the \rotatebox and suggest a fix? I will also appreciate any alternative markup.

3 Answers 3

5

You need to take care of the current math style:

\documentclass{article}
\usepackage{amsmath,amssymb,graphicx}

\newcommand{\vrt}{\shortmid}
\makeatletter
\newcommand{\hrz}{{\mathpalette\hrz@\relax}}
\newcommand{\hrz@}[2]{%
  \mspace{-1mu}%
  \rotatebox[origin=c]{90}{$\m@th#1\,\vrt$}%
  \mspace{-1mu}%
}
\makeatother

\begin{document}

$I^\hrz I^\vrt$

\end{document}

enter image description here

3

The reason why the rotated \shortmid seems larger is because the default math size setting within \rotatebox would be \textstyle, while it should be \scripstyle if you're using it in a superscript.

You could try with the following definitions of \vertical and \horizontal:

enter image description here

\documentclass{article}

\usepackage{amssymb,graphicx}

\newcommand{\horizontal}[1]{%
  #1^{\rotatebox[origin=c]{90}{$\scriptstyle\shortmid$}}
}
\newcommand{\vertical}[1]{%
  #1^{\shortmid}
}

\begin{document}

$\vertical{I}\ \horizontal{I}$

\end{document}
2
  • Thank you for your explanation, now I understand what's going on. However, because @egreg proposed a more general solution and also took care of positioning, I accepted his answer.
    – Eldrad
    Commented Nov 5, 2018 at 18:37
  • @Eldrad: Yes, that's great. I just answered the question. He went the extra mile.
    – Werner
    Commented Nov 5, 2018 at 19:04
3

Preserves the proper math style.

\documentclass{article}
\usepackage{amssymb,graphicx,scalerel}
\newcommand{\vrt}{\shortmid}
\newcommand{\hrz}{{\ThisStyle{\rotatebox[origin=c]{90}{$\SavedStyle\vrt$}}}}
\begin{document}
$I^\hrz I^\vrt$

$\scriptstyle I^\hrz I^\vrt$
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .