Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is it possible to get a \neq but with a vertical bar instead of a slanted one? There are inequality operators like AMS's \gvertneqq that feature this kind of "not equal" but not without mixing it with other signs.

\documentclass[a5paper]{article}
\usepackage{amssymb}
\usepackage{amsmath}
\begin{document}
\begin{align*}
a&\gvertneqq b\\
C&\neq \varnothing
\end{align*}
\end{document}

result of the above code

So what I basically would like to have is the isolated symbol under the > in the \gvertneqq above. Particularly because I don't like the different slopes of the slashes in the second line and "≠∅" is quite a common combination.

share|improve this question
add comment

4 Answers 4

up vote 17 down vote accepted

Equal sign with vertical line

The vertical line | is a little tall for my taste. The following definition for \vneq decreases the total height of the vertical line to match the total height of \neq. Resizing vertical height will not change the line thickness in horizontal direction.

  • The final witdh and height of the vertical line can be fine-tuned by redefining macros \vneqxscale and \vneqyscale. The default is 1.
  • \mathpalette allows the symbol to resize automatically.

Example file:

\documentclass{article}

\usepackage{amssymb}% \varnothing

\usepackage{graphicx}% \resizebox
\makeatletter
\newcommand*{\vneq}{%
  \mathrel{%
    \mathpalette\@vneq{=}%
  }%
}
\newcommand*{\@vneq}[2]{%
  % #1: math style (\displaystyle, \textstyle, ...)
  % #2: symbol (=, ...)
  \sbox0{\raisebox{\depth}{$#1\neq$}}%
  \sbox2{\raisebox{\depth}{$#1|\m@th$}}%
  \ifdim\ht2>\ht0 %
    \sbox2{\resizebox{\vneqxscale\width}{\vneqyscale\ht0}{\unhbox2}}%
  \fi
  \sbox2{$\m@th#1\vcenter{\copy2}$}%
  \ooalign{%
    \hfil\phantom{\copy2}\hfil\cr
    \hfil$#1#2\m@th$\hfil\cr
    \hfil\copy2\hfil\cr
  }%
}
\newcommand*{\vneqxscale}{1}
\newcommand*{\vneqyscale}{1}
\makeatother

\begin{document}
\[
  % Comparison \neq vs. vneq
  \varnothing \neq \emptyset \vneq \varnothing \\
\] 
\[ 
  % Check sizes:
  \vneq^{\vneq^{\vneq}} \\
\] 
\[ 
  % Bounding box checks:
  \setlength{\fboxsep}{0pt}
  \setlength{\fboxrule}{.1pt}
  \fbox{$\neq$}\,\fbox{$\vneq$}\,\fbox{$|$}
\]
\end{document}

Result

The height can be further decreased, e.g.

\renewcommand*{\vneqyscale}{.8}

Result/.8

Result for mathabx:

mathabx

Result for txfonts:

txfonts

Result for MnSymbol:

MnSymbol

Here the vertical line is too thick and the horizontal resizing needs shrinking:

\renewcommand*{\vneqxscale}{.67}

Result for MnSymbol and \vneqxscale = .67:

MnSymbol/.67

Alternative to varnothing

Instead of changing \neq, the empty set symbol \varnothing could be constructed using \not to match the slope of the slanted vertical lines. However, \circ is too small and \bigcirctoo big. Therefore this method is shown for txfonts that provides \medcirc and MnSymbol with \medcircle.

\documentclass{article}

%\usepackage{txfonts}
%\newcommand*{\varemptysetcircle}{\medcirc}

\usepackage{MnSymbol}
\newcommand*{\varemptysetcircle}{\medcircle}

\makeatletter
\newcommand*{\varemptyset}{%
  {% mathord
    \vphantom{\not=}% correct height and depth of the final symbol
    \mathpalette\@varemptyset\varemptysetcircle
  }%
}
\newcommand*{\@varemptyset}[2]{%
  % #1: math style (\displaystyle, \textstyle, ...)
  % #2: circle
  \ooalign{%
    \hfil$\m@th#1\not\hphantomeq$\hfil\cr
    \hfil$\m@th#1#2$\hfil\cr
  }%
}
% \not can be redefined to take an argument
\newcommand*{\hphantomeq}{%
  \mathrel{\hphantom{=}}%
}
\makeatother

\usepackage{color}

\begin{document}
\[
  \not=\; \color{blue}\neq \varemptyset\; \color{black}\varnothing
\]
\end{document}

Result for txfonts:

txfonts

Result for MnSymbol:

MnSymbol

share|improve this answer
    
This is just an amazing answer! I hope Werner won't mind that I couldn't but change the accepted answer to this one. I'm having some trouble when trying to \renewcommand \neq to this version of \vneq though. More specifically, I get a "TeX capacity exceeded". Any idea why? –  Christian Aug 29 '13 at 15:47
1  
\vneq is using \neq` in macro \@vneq. Thus you can store the old meaning: \let\ltxneq=\neq and use \ltxneq in \@vneq. Then you should be able to redefine \neq. –  Heiko Oberdiek Aug 29 '13 at 16:04
    
Ah, sure, I should have seen that! Thanks! –  Christian Aug 29 '13 at 19:22
add comment

Yes:

screenshot of code below

\documentclass[a5paper]{article}
\usepackage{amssymb}
\usepackage{amsmath}
\newcommand\vneq{\mathrel{\ooalign{$=$\cr\hidewidth$|$\hidewidth\cr}}}
\begin{document}
\begin{align*}
a&\gvertneqq b\\
C&\neq \varnothing \\
d&\vneq f
\end{align*}
\end{document}

For a motivation behind the commands in \vneq, read egreg's excellent tutorial on \ooalign in \subseteq + \circ as a single symbol (“open subset”)

share|improve this answer
    
Great, thanks! I added $$ around the = as well which becomes important when you have a different text than math font. Other than that this is a most elegant solution :) –  Christian Apr 11 '13 at 20:42
add comment

A simplistic solution would be

\usepackage{mathabx}
\changenotsign

but this would mean changing a great part of the math symbols, which is not desirable as, in my opinion, some of the symbols provided by mathabx are badly designed.

A solution with standard tools is

\documentclass{article}

\renewcommand\neq{\mathrel{\vphantom{|}\mathpalette\xsneq\relax}}
\newcommand\xsneq[2]{%
  \ooalign{\hidewidth$#1|$\hidewidth\cr$#1=$\cr}%
}

\begin{document}
$a\neq b$
\end{document}

I used \renewcommand because it will be simply a matter of removing that code in order to revert \neq to its usual shape.

By using \mathpalette, the created symbol will become smaller in subscripts or superscripts.

enter image description here

share|improve this answer
    
both this symbol and an equals sign with a back-slanted cancellation are included in the stix fonts. –  barbara beeton Aug 25 '13 at 20:50
    
@barbarabeeton Yes, but those fonts don't mix well with Computer Modern and other fonts. –  egreg Aug 25 '13 at 20:53
    
sad but true. they were designed to mix with times, which was the consensus typeface of the stipub consortium members. –  barbara beeton Aug 25 '13 at 20:55
add comment

You can use the cancel package. This makes you able to cancel all terms and symbols you want.

share|improve this answer
5  
The bar made by the cancel package is never vertical. –  egreg Aug 25 '13 at 22:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.