We consider the approximate computation of spectral projectors for symmetric banded matrices. While this problem has received considerable attention, especially in the context of linear scaling electronic structure methods, the presence of small relative spectral gaps challenges existing methods based on approximate sparsity. In this work, we show how a data-sparse approximation based on hierarchical matrices can be used to overcome this problem. We prove a priori bounds on the approximation error and propose a fast algorithm based on the QR-based dynamically weighted Halley (QDWH) algorithm, along the lines of works by Nakatsukasa and colleagues. Numerical experiments demonstrate that the performance of our algorithm is robust with respect to the spectral gap. A preliminary MATLAB implementation becomes faster than eig already for matrix sizes of a few thousand.