Inhomogeneous phases at finite density in an external magnetic field