The NMR chemical shift spectra of diamond, chemical-vapor-deposited (CVD) diamond, and diamondlike amorphous carbon are computed from first principles. The results of our calculation are in excellent agreement with experiments, and are useful for the interpretation of the NMR spectra in terms of the microscopic structure of the materials. In particular, we show that the NMR and Raman linewidths in polycrystalline CVD diamond are due to stress fluctuations, and we support a heterogeneous model for the amorphous hydrogenated phase. [S0031-9007(97)04072-6] PACS numbers: 76.60. Cq, 61.43.Bn, 71.15.Mb, 82.80.Ch Polycrystalline diamond thin films, grown by chemical vapor deposition (CVD), and diamondlike amorphous carbon thin films possess the outstanding physical properties of bulk diamond, such as high thermal conductivity, hardness, chemical inertness, and optical transparency in the infrared region. Their possible applications include wear-resistant coatings and thin-film semiconductor devices. For example, diamondlike amorphous carbon is currently used as a protective layer in magnetic disks. Considerable efforts have been undertaken to understand the microscopic structure of these films. Nuclear magnetic resonance (NMR) is becoming increasingly important in this investigation, especially for the characterization of amorphous carbon [1-4], but also for the study of CVD diamond [5,6]. In Ref.[7] we presented a novel theory for the ab initio computation of NMR chemical shifts (s) in condensed matter systems. Our formalism overcomes the limitations of all previous approaches [8], which could handle only isolated molecules or clusters, and it can be applied to periodic crystals or, with a supercell technique, to amorphous materials. In this Letter we present the first ab initio calculations of carbon chemical shifts in crystalline and amorphous solids. We compute the chemical shift spectra of diamond, CVD diamond, and diamondlike amorphous carbon with and without hydrogen. Our results are in excellent agreement with experiments, and are useful for the interpretation of NMR spectra in terms of the microscopic structure of the materials.A uniform, external magnetic field B ext applied to a sample of matter induces an electronic current which produces a nonuniform magnetic field, B in ͑r͒. The chemical shift is defined as the ratio between the induced magnetic field and the external uniform applied magnetic field,Here s $ ͑r͒ is the chemical shift tensor, and s͑r͒ Tr͓s $ ͑r͔͒͞3. This magnetic response is a fingerprint of the microscopic structure of the material under study. NMR measures s͑r͒ at the nuclear positions. We denote with H s the chemical shifts at the hydrogen nuclei, and with C s the chemical shifts at the carbon nuclei.We compute s following Ref.[7]. The electronic structure is described using density functional theory in the local density approximation. As the core contributions for C are insensitive to the chemical environment [8], we consider the magnetic response of the valence electrons only. We use...