The possibility of spontaneous periodic distortions, depending on the tilt angle in a nematic liquid crystal sample, is investigated by means of a general formulation of the stability problem. It is shown that due to the presence of a surfacelike term in the free-energy density, the uniform pattern can be destabilized, giving rise to a periodic distortion of the director. Our analysis establishes, in general terms, the conditions for the formation of stable periodic structures in nematic samples. In particular, we determine the wavelengths for which the periodic distortion exists by investigating its dependence on the tilt angle, characterizing the uniform pattern, and on the saddle-splay elastic constant. The effect considered in our paper is a finite size effect, related to the slab geometry of the nematic sample under consideration.