Patient motion, especially respiratory motion, results in various artefacts such as blurring and streaks in tomographic images. The interplay of the movement of the beam aperture and variations of organ anatomy during delivery can create 'hot' and 'cold' spots throughout the field in intensity-modulated radiation therapy (IMRT). Detection and correction of patient motion is extremely important in tomographic imaging and IMRT. Tomographic projection data (sinogram) encode not only the patient anatomy information, but also the intra-scanning motion information. In this paper, we developed an algorithm to detect and correct the in-plane respiratory motion directly in sinogram space. The respiratory motion is modelled as time-varying scaling along the x and y directions. Its effects on the sinogram are discussed. Based on the traces of some nodal points in the sinogram, the intra-scanning motion is determined. The motion correction is also implemented in sinogram space. The motion-corrected sinogram is used for reconstruction by the filtered back-projection (FBP) method. Computer simulations validate the motion detection and correction algorithm. The reconstructed images from the motion-corrected sinogram eliminate the majority of the artefacts. The method could be applied to projection data used in CT and ECT, as well as in tomotherapy delivery modification and dose reconstruction.