  We investigate the fine and spin structure of ultralong-range Rydberg
molecules exposed to a homogeneous magnetic field. Each molecule consists of a
$^{87}$Rb Rydberg atom whose outer electron interacts via spin-dependent $s$-
and p-wave scattering with a polarizable $^{87}$Rb ground state atom. Our model
includes also the hyperfine structure of the ground state atom as well as
spin-orbit couplings of the Rydberg and ground state atom. We focus on
$d$-Rydberg states and principal quantum numbers $n$ in the vicinity of 40. The
electronic structure and vibrational states are determined in the framework of
the Born-Oppenheimer approximation for varying field strengths ranging from a
few up to hundred Gau{\ss}. The results show that the interplay between the
scattering interactions and the spin couplings gives rise to a large variety of
molecular states in different spin configurations as well as in different
spatial arrangements that can be tuned by the magnetic field. This includes
relatively regularly shaped energy surfaces in a regime where the Zeeman
splitting is large compared to the scattering interaction but small compared to
the Rydberg fine structure, as well as more complex structures for both, weaker
and stronger fields. We quantify the impact of spin couplings by comparing the
extended theory to a spin-independent model.
