Centering a slash (not) over a (mathematical) glyph?
Don't reinvent the wheel. ;-)
\documentclass{article}
\usepackage{centernot}
\begin{document}
$\centernot{\infty}$
\end{document}
Some manual adjusting can help:
\documentclass{article}
\usepackage{centernot}
\begin{document}
$\centernot{\mkern-0.35mu\infty}\mkern-0.35mu$
\end{document}
Finding the exact geometric center is not really easy, because it depends on the side bearings of the symbol. Here's a picture showing them
Also the slash has side bearings, so it's a question of balancing them.
Of course, when you're satisfied with the positioning, you can define
\newcommand{\cinfty}{\mathrel{\centernot{\mkern-0.35mu\infty}\mkern-0.35mu}}
A different version that uses the slash rather than \not
(and my favorite tool \ooalign
).
\documentclass{article}
\makeatletter
\newcommand{\cinfty}{\mathrel{\mathpalette\do@cinfty\relax}}
\newcommand{\do@cinfty}[2]{%
\vphantom{/}%
\ooalign{\hidewidth$\m@th#1/$\hidewidth\cr$\m@th#1\infty$}%
}
\begin{document}
$A\cinfty B_{\cinfty}$
\end{document}
\documentclass{article}
\usepackage{stackengine}
\renewcommand\stacktype{L}
\stackMath
\begin{document}
$\stackon[0pt]{\infty}{/}$
\end{document}
If you want the version that is a \mathrel
and scales with the math style,
\documentclass{article}
\usepackage{scalerel,stackengine}
\def\notinfty{%
\renewcommand\stacktype{L}\mathrel{\ensurestackMath{%
\ThisStyle{\stackon[0pt]{\SavedStyle\infty}{\SavedStyle/}}}}%
}
\begin{document}
$A \notinfty B ~\scriptstyle A\notinfty B ~\scriptscriptstyle A \notinfty B$
\end{document}
\not
is usually optimized for the equals sign. Package centernot
takes care of the horizontal centering. \infty
is wider than the equals sign, see egreg's answer.
The equals sign is vertically centered around the math axis and \not
usually follows this symmetry. The symbol \infty
, however, just sits on the base line (Computer Modern fonts, cmsy10
). Since it seems used with a different meaning as relational symbol, it might be allowed to vertically center it.
The following example centers \infty
as \vinfty
vertically around the math axis and uses package centernot
for the horizontal centering.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[variablett]{lmodern}
\usepackage{amsmath}% for environment "gather*"
\usepackage{centernot}
\makeatletter
\newcommand*{\vinfty}{%
\mathrel{%
\mathpalette\@vinfty{}%
}%
}
\newcommand*{\@vinfty}[2]{%
% #1: math style
% #2: unused
\vcenter{%
\hbox{$#1\infty\m@th$}%
}%
}
\makeatother
\newcommand*{\notvinfty}{%
\centernot\vinfty
}
\begin{document}
\centering
{\scriptsize Vertically centered (\texttt{\textbackslash vinfty})}
\begin{gather*}
a \vinfty b \notvinfty c
\\
\scriptstyle a \vinfty b \notvinfty c
\\
\scriptscriptstyle a \vinfty b \notvinfty c
\end{gather*}
%
{\scriptsize Not vertically centered (\texttt{\textbackslash infty})}
\begin{gather*}
a \mathrel{\infty} b \centernot\infty c
\\
\scriptstyle a \mathrel{\infty} b \centernot\infty c
\\
\scriptscriptstyle a \mathrel{\infty} b \centernot\infty c
\end{gather*}
\end{document}