Distance minimizers in $L^1$ and $L^{\infty}$

Here is an example in $L^1[0,1]$. Let $K$ be the set of functions $f\in L^1[0,1]$ such that $\int_0^1 xf(x)\,dx=0$. This is a closed subspace of $L^1$. Consider the distance from $g(x)=1$ to $K$. For any $f\in K$ we have $$ \left|\int_0^1 x(f(x)-1)\,dx \right| = \int_0^1 x\,dx =\frac12 \tag{1} $$ Since $x<1$ a.e., it follows that $$ \int_0^1 |f(x)-1|\,dx > \int_0^1 x|f(x)-1|\,dx \ge \frac12 \tag{2} $$ On the other hand, the sequence $$ f_n(x) = 1 - \frac{n^2}{2n-1}\chi_{[1-1/n,1]} \tag{3} $$ belongs to $K$ and satisfies $\|f_n-g\|_{L^1}\to \frac12$. Therefore, $\operatorname{dist}(g,K)=1/2$ and this distance is not attained.


I don't have an explicit example in $L^\infty$, but since $L^\infty$ contains an isometric copy of every separable Banach space, one can use an isometric embedding $\phi : L^1\to L^\infty$ to produce an implicit example: $\phi(g)$ and $\phi(K)$. Since $K$ is a complete metric space, its image $\phi(K)$ is a closed subspace of $L^\infty$.