Matter-wave near-field interferometric experiments require interference contrast as high as possible in order to extract information from the interference patterns. One of the tasks to accomplish this requirement is to align the distances between gratings and detection. We present here a method for this precision alignment. An electron beam as a matter-wave source, a diffraction grating, and mask grating were used in this study. The simulations show that the longitudinal scanning of the mask grating with the detection can specify the exact location of the near-field or so-called Talbot distance with the condition of using the gratings with small open fractions. Therefore, the various open fractions were done in the calculation. Due to the lack of commercial gratings with small open fractions, a technique of two overlapping gratings can be applied for changing arbitrary grating shapes and open fractions. We conclude that smaller open fraction of the gratings gives better longitudinal alignment. The results show that the Talbot distance is located at the highest throughput behind the gratings. The present study can provide a method for implementing matter-wave diffraction experiments in the future.