A variational approach for the semivectorial modal analysis of dielectric waveguides with arbitrary piecewise constant rectangular 2D cross-sections is developed. It is based on a representation of a mode profile as a superposition of modes of constituting slab waveguides times some unknown continuous coefficient functions, defined on the entire coordinate axis. The propagation constant and the lateral functions are found from a variational principle. It appears that this method with one or two modes in the expansion preserves the computational efficiency of the standard effective index method while providing more accurate estimates for propagation constants, as well as well-defined continuous approximations for mode profiles. By including a larger number of suitable trial fields, the present approach can also serve as a technique for rigorous semivectorial mode analysis.