© 2017 authors. Published by the American Physical Society. Published by the American Physical Society under the terms of the https://creativecommons.org/licenses/by/4.0/ Creative Commons Attribution 4.0 International license. Further distribution of this work must maintain attribution to the author(s) and the published article's title, journal citation, and DOI. Plasma-based accelerators offer the possibility to drive future compact light sources and high-energy physics applications. Achieving good beam quality, especially a small beam energy spread, is still one of the major challenges. Here, we propose to use a periodically modulated plasma density to shape the longitudinal fields acting on an electron bunch in the linear wakefield regime. With simulations, we demonstrate an on-average flat accelerating field that maintains a small beam energy spread.