# How to denote adjacent vertices?

### Background

I'm trying to write a rapport that relies on some rudimentary graph theory and as such I'd like to write a section explaining the basics of it.

### Trying to do

I've run into a bit of a snag trying to adequately write out pairs of vertices that have an edge between them. Hopefully someone more knowledgeable in regards to TeX either knows of the command which I seek or of a way to create it:

I mean to write vertices u and v (in math-mode) with a long line between them, approximately the distance of an em-dash. This line denotes an edge between the vertices. However I need to be able to also denote the lack of such an edge by being able to strike over said line (\not). Any and all help would be much appreciated!

### Tested

I've tried

$u \not\textemdash v$


and

$u \not\textrm{---} v$
$u \not\textrm{\textemdash} v$


however neither works. The latter two are close but I'd need to be able to move the symbol generated by \not to the right by about half an em somehow.

You could use \arrownot from stmaryrd; the normal \not seems too big for a simple bar.

\documentclass{article}
\usepackage{stmaryrd} % for \arrownot
\newcommand{\notedge}{%
\mathrel{\mkern-2mu}% a small back up
\arrownot % a short slash
\mathrel{\mkern2mu}% compensate
\mathrel{-}% minus as a relation
}

\begin{document}
$u\notedge v$
\end{document}


This exploits two facts: \arrownot has zero width and is classified as a relation symbol (it extends past its bounding box); TeX doesn't add space between consecutive relation symbols (which can also be spaces)

This is how $u\not\mathrel{-}v$ would print:

A possible alternative:

\documentclass{article}
\usepackage{centernot}

\newcommand{\notedge}{\centernot{\mathrel{-}\joinrel\mathrel{-}}}

\begin{document}

$u\notedge v$

\end{document}


Another proposal with longer symbols:

\documentclass{article}

\usepackage{stmaryrd} % for \arrownot

\newcommand{\edge}{%
\mathrel{-}% minus as a relation
\joinrel\joinrel % some backup
\mathrel{-}% minus as a relation
}
\newcommand{\notedge}{%
\arrownot % a short slash
\mathrel{\mkern-2mu}% compensate
\edge
}

\begin{document}

$u \edge v$

$u\notedge v$

\end{document}


centernot provides centering of \not across lengthier symbols:

\documentclass{article}
\usepackage{centernot}% http://ctan.org/pkg/centernot
\begin{document}
$u \adjacent v \notadjacent w \adjacent[1em] x \notadjacent[1em] y$
\end{document}


Both \adjacent[<len>] and \nonadjacent[<len>] take an optional argument with the defauly being .7em.

• This is, like the above, an excellent answer. Unfortunately I'm new on TeX.sx and cannot give you the vote up that you deserve. But thank you. – user47101 Feb 28 '14 at 22:16

This is late, but I made these symbols that I use to differentiate between undirected, directed, and their weighted counterparts.

\usepackage{tikz}

\newcommand{\ue}[1]{%
\begin{tikzpicture}[#1]%
\draw[fill = black] (.25ex,.25ex) circle (.3ex);
\draw[thick] (.55ex,.25ex) -- (1.55ex,.25ex);%
\draw[fill = black] (1.85ex, .25ex) circle (.3ex);%
\end{tikzpicture}%
}

\newcommand{\de}[1]{%
\begin{tikzpicture}[#1]%
\draw[fill = black] (.25ex,.25ex) circle (.3ex);
\draw[thick, ->] (.55ex,.25ex) -- (1.85ex,.25ex);%

\end{tikzpicture}%
}