Strain engineering enables modification of the properties of thin films using the stress from the substrates on which they are grown. Strain may be relaxed, however, and this can also modify the properties thanks to the coupling between strain gradient and polarization known as flexoelectricity. Here we have studied the strain distribution inside epitaxial films of the archetypal ferroelectric PbTiO3, where the mismatch with the substrate is relaxed through the formation of domains (twins). Synchrotron X-ray diffraction and high-resolution scanning transmission electron microscopy reveal an intricate strain distribution, with gradients in both the vertical and, unexpectedly, the horizontal direction. These gradients generate a horizontal flexoelectricity that forces the spontaneous polarization to rotate away from the normal. Polar rotations are a characteristic of compositionally engineered morphotropic phase boundary ferroelectrics with high piezoelectricity; flexoelectricity provides an alternative route for generating such rotations in standard ferroelectrics using purely physical means.