The processing of quantum information based on the electron spin degree of freedom requires fast and coherent manipulation of local spins. One approach is to provide spatially selective tuning of the spin splitting--which depends on the g-factor--by using magnetic fields, but this requires their precise control at reduced length scales. Alternative proposals employ electrical gating and spin engineering in semiconductor heterostructures involving materials with different g-factors. Here we show that spin coherence can be controlled in a specially designed AlxGa1-xAs quantum well in which the Al concentration x is gradually varied across the structure. Application of an electric field leads to a displacement of the electron wavefunction within the quantum well, and because the electron g-factor varies strongly with x, the spin splitting is therefore also changed. Using time-resolved optical techniques, we demonstrate gate-voltage-mediated control of coherent spin precession over a 13-GHz frequency range in a fixed magnetic field of 6 T, including complete suppression of precession, reversal of the sign of g, and operation up to room temperature.