Ecologists still search for common principles that predict well-known responses of biological diversity to different factors. Such factors include the number of available niches in space, productivity, area, species' body size and habitat fragmentation. Here we show that all these patterns can arise from simple constraints on how organisms acquire resources in space. We use spatial scaling laws to describe how species of different sizes find food in patches of varying size and resource concentration. We then derive a mathematical rule for the minimum similarity in size of species that share these resources. This packing rule yields a theory of species diversity that predicts relations between diversity and productivity more effectively than...