In intermetallic compounds with zero orbital momentum $(L=0)$ the magnetic anisotropy and the electronic band structure are interconnected. Here, we investigate this connection in divalent Eu and trivalent Gd intermetallic compounds. We find by x-ray magnetic circular dichroism an out-of-plane easy magnetization axis in two-dimensional atom-thick ${\mathrm{EuAu}}_{2}$. Angle-resolved photoemission spectroscopy and density-functional theory prove that this is due to strong $f\text{\ensuremath{-}}d$ band hybridization and ${\mathrm{Eu}}^{2+}$ valence. In contrast, the easy in-plane magnetization of the structurally equivalent ${\mathrm{GdAu}}_{2}$ is ruled by spin-orbit-split $d$ bands, notably Weyl nodal lines, occupied in the ${\mathrm{Gd}}^{3+}$ state. Regardless of the $L$ value, we predict a similar itinerant electron contribution to the anisotropy of analogous compounds.