We theoretically and experimentally study nematic liquid crystal equilibria within shallow rectangular wells. We model the wells within a two-dimensional Oseen–Frank framework, with strong tangent anchoring, and obtain explicit analytical expressions for the director fields and energies of the ‘diagonal’ and ‘rotated’ solutions reported in the literature. These expressions separate the leading-order defect energies from the bulk distortion energy for both families of solutions. The continuum Oseen–Frank study is complemented by a microscopic mean-field approach. We numerically minimize the mean-field functional, including the effects of weak anchoring, variable order and random initial conditions. In particular, these simulations suggest the existence of higher-energy metastable states with internal defects. We compare our theoretical results to experimental director profiles, obtained using two types of filamentous virus particles, wild-type fd-virus and a modified stiffer variant (Y21M), which display nematic ordering in rectangular chambers, as found by confocal scanning laser microscopy. We combine our analytical energy expressions with experimentally recorded frequencies of the different equilibrium states to obtain explicit estimates for the extrapolation length, defined to be the ratio of the nematic elastic constant to the anchoring coefficient, of the fd-virus.