We present a trajectory dynamically tracing compensation method to smooth the spatial fluctuation of the static magnetic field (C-field) that provides a quantization axis in the fountain clock. The C-field coil current is point-to-point adjusted in accordance to the atoms experienced magnetic field along the flight trajectory. A homogeneous field with a 0.2 nT uncertainty is realized compared to 5 nT under the static magnetic field with constant current during the Ramsey interrogation. The corresponding uncertainty associated with the second-order Zeeman shift that we calculate is improved by one order of magnitude. The technique provides an alternative method to improve the magnetic field uniformity particularly for large-scale equipment that is difficult to machine with magnetic shielding. Our method is simple, robust, and essentially important in frequency evaluations concerning the dominant uncertainty contribution due to the quadratic Zeeman shift.