= Solution
Fix $x\in X$ and choose affine opens $x\in U\subseteq X$ and $f(x)\in W\subseteq S$ with $f(U)\subseteq W$. The open subset $U\times_WU$ of $X\times_SX$ contains $\Delta(x)$. If $U=\operatorname{Spec}A$ and $W=\operatorname{Spec}R$, its diagonal is induced by the surjection
$$
A\otimes_RA\longrightarrow A,
\qquad a\otimes b\longmapsto ab,
$$
so it is a closed immersion. Hence every <diagonal morphism> is locally a closed immersion into an open subset, and therefore is a <locally closed immersion>.
For $\mathbb A_k^1$, the product is $\mathbb A_k^2=\operatorname{Spec}k[x,y]$ and the diagonal is $V(x-y)$. Its complement is the principal affine open
$$
\boxed{D(x-y)=\operatorname{Spec}k[x,y,(x-y)^{-1}].}
$$
Take instead the separated scheme $X=\mathbb A_k^2$. The complement of its diagonal in $X\times_kX\cong\mathbb A_k^4$ is $\mathbb A_k^4\setminus\mathbb A_k^2$, where the removed diagonal has codimension two. Its global functions still form the polynomial ring of $\mathbb A_k^4$. Were the complement affine, its canonical morphism to $\operatorname{Spec}$ of this ring would identify it with all of $\mathbb A_k^4$, which is impossible. Thus this diagonal complement is not affine.
Back to article page