We present results for the optical absorption spectra of small-diameter single-wall carbon and boron nitride nanotubes obtained by {it ab initio} calculations in the framework of time-dependent density functional theory. We compare the results with those obtained for the corresponding layered structures, i.e. the graphene and hexagonal BN sheets. In particular, we focus on the role of depolarization effects, anisotropies and interactions in the excited states. We show that already the random phase approximation reproduces well the main features of the spectra when crystal local field effects are correctly included, and discuss to which extent the calculations can be further simplified by extrapolating results obtained for the layered systems to results expected for the tubes. The present results are relevant for the interpretation of data obtained by recent experimental tools for nanotube characterization such as optical and fluorescence spectroscopies as well as polarized resonant Raman scattering spectroscopy. We also address electron energy loss spectra in the small-q momentum transfer limit. In this case, the interlayer and intertube interactions play an enhanced role with respect to optical spectroscopy.