We treat the trapping of resonance radiation in a plane-parallel slab geometry, emphasizing the importance of higher-order spatial modes of excited atoms. The whole range of opacities and all commonly encountered line shapes (single or hyperfine-split spectral lines of Lorentzian, Doppler, or Voigt profiles) are covered. For the basic line shapes (Doppler and Lorentz), we solve the Holstein-Biberman equation numerically and give simple analytic fitting formulas for the shape and the trapping factor of the ground mode and higher-order modes. The results are checked and extended to more general line shapes with a quite different approach, a Monte-Carlo simulation. For the treatment of Voigt profiles, we modify common interpolation formulas for the trapping factor to make them applicable at all opacities. We critically review the Milne-Samson theory that is often used in the low-opacity regime for arbitrarily complicated lineshapes; a new definition of the equivalent opacity considerably increases its range of applicability. Almost all practically occurring radiation-trapping problems in a plane-parallel slab geometry can be treated with the present approach.