We present a generalized piecewise polytropic parametrization for the neutron-star equation of state using an ansatz that imposes continuity in not only pressure and energy density, but also in the speed of sound. The universe of candidate equations of state is shown to admit preferred dividing densities, determined by minimizing an error norm consisting of integral astrophysical observables. Generalized piecewise polytropes accurately reproduce astrophysical observables, such as mass, radius, tidal deformability and mode frequencies, as well as thermodynamic quantities, such as the adiabatic index. This makes the new equations of state useful for parameter estimation from gravitational waveforms. Since they are differentiable, generalized piecewise polytropes can improve pointwise convergence in numerical relativity simulations of neutron stars. Existing implementations of piecewise polytropes can easily accommodate this generalization with the same number of free parameters. Optionally, generalized piecewise polytropes can also accommodate adjustable jumps in sound speed, which allows them to capture phase transitions in neutron star matter.