Malnutrition is a commonly observed side effect in cancer patients, with a 30-85% worldwide prevalence in this population. Existing malnutrition screening tools miss ~ 20% of at-risk patients at initial screening and do not capture the abnormal body composition phenotype. Meanwhile, the gold-standard clinical criteria to diagnose malnutrition use changes in body composition as key parameters, particularly body fat and skeletal muscle mass loss. Diagnostic imaging, such as computed tomography (CT), is the gold-standard in analyzing body composition and typically accessible to cancer patients as part of the standard of care. In this study, we developed a deep learning-based body composition analysis approach over a diverse dataset of 200 abdominal/pelvic CT scans from cancer patients. The proposed approach segments adipose tissue and skeletal muscle using Swin UNEt TRansformers (Swin UNETR) at the third lumbar vertebrae (L3) level and automatically localizes L3 before segmentation. The proposed approach involves the first transformer-based deep learning model for body composition analysis and heatmap regression-based vertebra localization in cancer patients. Swin UNETR attained 0.92 Dice score in adipose tissue and 0.87 Dice score in skeletal muscle segmentation, significantly outperforming convolutional benchmarks including the 2D U-Net by 2-12% Dice score (p-values < 0.033). Moreover, Swin UNETR predictions showed high agreement with ground-truth areas of skeletal muscle and adipose tissue by 0.7-0.93 R2, highlighting its potential for accurate body composition analysis. We have presented an accurate body composition analysis based on CT imaging, which can enable the early detection of malnutrition in cancer patients and support timely interventions.