The patterning of x-ray grating surfaces by electron-beam lithography offers large flexibility to realize complex optical functionalities. Here, we report on a proof-of-principle experiment to demonstrate the correction of slope errors of the substrates by modulating the local density of the grating lines. A surface error map of a test substrate was determined by optical metrology and served as the basis for an aligned exposure of a corrected grating pattern made by electron-beam lithography. The correction is done by a variation of the local line density in order to compensate for the local surface error. Measurements with synchrotron radiation and simulations in the soft X-ray range confirm that the effects of slope errors were strongly reduced over an extended wavelength range.