# Overlay a 0 with a |

How can I overlay a 0 with a | in latex to create a new symbol comprised of a 0 with a vertical line inside it?

I've looked at the following post Overlay symbol with another and tried to adapt the code provided in one of the answers, because I didn't understood the accepted answer, but this did not output the symbol that I wanted.

\newcommand\cz{\mathrel{\ooalign{$|$\cr\hidewidth$0$\hidewidth\cr}}}


The vertical dash would go out of the zero and when I wrote another letter next to this symbol the spacing would be incorrect. In order to try and understand the accepted answer I tried to look for the commands used there, like \rlap, \setbox, ..., in the web and in the latex reference provided with texmaker under the help tab but the web pages I found explainde very poorly these commands and the latex refence didn't even had them. Where can I find the official documentation for these commands or any other good resource to learn them?

Made to work in all math styles. I overlay a stretched \vert inside a 0.

\documentclass{article}
\usepackage{stackengine,scalerel}
\newcommand\vertzero{\ThisStyle{\ensurestackMath{\stackengine
{0pt}{\SavedStyle0}{\SavedStyle\stretchrel*{\vert}{0}}%
{O}{c}{F}{F}{L}}}}
\begin{document}
$\vertzero\scriptstyle\vertzero\scriptscriptstyle\vertzero$
\end{document}


If one did not like seeing, under high magnification, the rounded extrema of the \vert, one could tweak it as

\documentclass{article}
\usepackage{stackengine,scalerel}
\newcommand\vertzero{\ThisStyle{\ensurestackMath{\stackengine
{0pt}{\SavedStyle0}%
{O}{c}{F}{F}{L}}}}
\begin{document}
$\vertzero\scriptstyle\vertzero\scriptscriptstyle\vertzero$
\end{document}


If one wanted more control over the width of the bar, replacing the \vert with a \rule of specified width would provide that flexibility. Here, I make the width .6\LMpt, where \LMpt is a measure of pt that is scaled in the smaller math styles.

\documentclass{article}
\usepackage{stackengine,scalerel}
\newcommand\vertzero{\ThisStyle{\ensurestackMath{\stackengine
{0pt}{\SavedStyle0}{\SavedStyle\stretchrel*{\rule{.6\LMpt}{1ex}}{0}}%
{O}{c}{F}{F}{L}}}}
\begin{document}
$\vertzero\scriptstyle\vertzero\scriptscriptstyle\vertzero$
\end{document}


• Thank you very much, it's exactly what I needed. Also do you know a good resource to learn about the commands you used in the \newcommand line? I'm a newcomer to latex and only know the basics of the basics. Sep 14, 2021 at 14:22
• @DiogoSantos The manuals for those two packages can be found at ctan.org/pkg/stackengine and ctan.org/pkg/scalerel. Stackengine is for stacking objects (to include overlaying), while scalerel is for scaling and stretching of objects, for example, to match the size of another specified object. Sep 14, 2021 at 14:23

With \ooalign, but resizing the bar to fit. I use a simple \vrule of the appropriate height and as wide as fraction lines in the current math style.

Note that \hidewidth has to be used for the narrower symbol.

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

\makeatletter
\newcommand{\cz}{}% for safety
\DeclareRobustCommand{\cz}{\mathord{\mathpalette\cz@\relax}}
\newcommand{\cz@}[2]{%
\begingroup
\sbox\z@{$\m@th#10$}%
\ooalign{%
\hidewidth\vrule height \ht\z@ width \cz@wd{#1}\hidewidth\cr
\box\z@\cr
}%
\endgroup
}
\newcommand{\cz@wd}[1]{%
\fontdimen8
\ifx#1\displaystyle\textfont\else
\ifx#1\textstyle\textfont\else
\ifx#1\scriptstyle\scriptfont\else
\scriptscriptfont\fi\fi\fi 3
}
\makeatother

\begin{document}

$0+\cz$

$\scriptstyle 0+\cz$

$\scriptscriptstyle 0+\cz$

\end{document}


Here I use TikZ to draw the line:

\documentclass{article}
\usepackage{tikz}
\newcommand{\zerobar}{
\begin{tikzpicture}[baseline, overlay]
\node[anchor=base] {$0$};
\draw (0,0) -- (0,1.5ex);
\end{tikzpicture}
}
\begin{document}
Test \zerobar{} test $0$ test
\end{document}


Edit: Better spacing:

\documentclass{article}
\usepackage{tikz}
\newcommand{\zerobar}{%
\begin{tikzpicture}[baseline]
\node[anchor=base, inner sep=0] {$0$};
\draw (0,0) -- (0,1.5ex);
\end{tikzpicture}}
\begin{document}
Test in text \zerobar{} test $0$ test\\
Test in math $\zerobar{}+2=0+2$
\end{document}