Lemma 30.13.3. Let $S$ be a scheme. Let $Z \subset S$ be a locally principal closed subscheme. Let $U = S \setminus Z$. Then $U \to S$ is an affine morphism.

Proof. The question is local on $S$, see Morphisms, Lemmas 28.11.3. Thus we may assume $S = \mathop{\mathrm{Spec}}(A)$ and $Z = V(f)$ for some $f \in A$. In this case $U = D(f) = \mathop{\mathrm{Spec}}(A_ f)$ is affine hence $U \to S$ is affine. $\square$

In your comment you can use Markdown and LaTeX style mathematics (enclose it like $\pi$). A preview option is available if you wish to see how it works out (just click on the eye in the toolbar).