1. A method for homogenizing a static magnetic field having a distribution B0(r) in an active volume of a magnetic resonance apparatus, the magnetic resonance apparatus having a number N of shim coils, the method comprising the steps of: a) mapping the magnetic field distribution B0(r) of the static magnetic field; b) defining a target field distribution B0T(r) using an optimization procedure to optimize a numerical quality criterion for the target field distribution B0T(r), the optimization procedure supplying values for currents through the N shim coils, wherein a spatial weighting function is used in the optimization procedure, the optimization procedure further comprising a filter method in which a norm of the currents in the shim coils is influenced by means of filter factors, wherein the optimization procedure works in a parameter space having M control parameters with 2≦M<N, one of the control parameters being used as a weighting parameter for modification of a spatial weighting function, wherein an additional control parameter controls the filter factors; and c) generating, following step b), the target field distribution B0T(r) in the active volume by setting the currents in the shim coils.