We investigate the effect of the interlayer interaction on the structural and electronic properties of layered MX2(M=Ti, Zr, Hf, Cr, Mo, W) structures with van der Waals interaction. We calculate the relative stability of various layer-layer stacking configurations determined by considering relative positions and orientations between neighboring layers. It is found that an intriguing coupling effect between stacking and electronic structure. Some stacking configuration with a lager inter-layer distance exhibit larger electronic band gap than the other structures.