  We analyze the stellar abundances of massive galaxies ($\log
M_\ast/M_\odot>10.5$) at $z=2$ in the IllustrisTNG simulation with the goal of
guiding the interpretation of current and future observations, particularly
from the James Webb Space Telescope. We find that the effective size, $R_e$, of
galaxies strongly affects the abundance measurements: both [Mg/H] and [Fe/H]
are anti-correlated with $R_e$, while the relative abundance [Mg/Fe] slightly
increases with $R_e$. The $\alpha$ enhancement as tracked by [Mg/Fe] traces the
formation timescale of a galaxy weakly, and mostly depends on $R_e$. Aperture
effects are important: measuring the stellar abundances within 1~kpc instead of
within $R_e$ can make a large difference. These results are all due to a nearly
universal, steeply declining stellar abundance profile that does not scale with
galaxy size -- small galaxies appear metal-rich because their stars live in the
inner part of the profile where abundances are high. The slope of this profile
is mostly set by the gas-phase abundance profile and not substantially modified
by stellar age gradients. The gas-phase abundance profile, in turn, is
determined by the strong radial dependence of the gas fraction and star
formation efficiency. We develop a simple model to describe the chemical
enrichment, in which each radial bin of a galaxy is treated as an independent
closed-box system. This model reproduces the gas-phase abundance profile of
simulated galaxies, but not the detailed distribution of their stellar
abundances, for which gas and/or metal transport are likely needed.
