7

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.

5

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}

enter image description here

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:

enter image description here

A possible alternative:

\documentclass{article}
\usepackage{centernot}

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

\begin{document}

$u\notedge v$

\end{document}

enter image description here

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}{%
  \mathrel{\mkern2mu}% a small advancement
  \arrownot % a short slash
  \mathrel{\mkern-2mu}% compensate
  \edge
}

\begin{document}

$u \edge v$

$u\notedge v$

\end{document}

enter image description here

3

centernot provides centering of \not across lengthier symbols:

enter image description here

\documentclass{article}
\usepackage{centernot}% http://ctan.org/pkg/centernot
\newcommand{\adjacent}[1][.7em]{\mathrel{\rule[.5ex]{#1}{.4pt}}}
\newcommand{\notadjacent}[1][.7em]{\mathrel{\centernot{\adjacent[#1]}}}
\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
1

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

enter image description here enter image description here enter image description here

\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}%
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy