The ability of a sensor node to determine its position is a fundamental requirement for many applications in wireless sensor networks (WSNs). In this article, we address a scenario where a subset of sensors, called anchor nodes, knows its own position and helps other nodes determine theirs through range-based positioning techniques. Such techniques benefit from a high degree of connectivity, since range measurements from at least four anchor nodes are necessary (three-dimensional scenario). On the other hand, WSN topologies, most notably the cluster-tree topology, tend to limit connectivity between nodes to save energy. This results in very poor performance of the network in terms of localization. In this article, we propose LACFA, a network formation algorithm that increases the probability of localization of sensors in a cluster-tree topology. It does so by properly allocating anchor nodes to different clusters during the network formation phase. Our algorithm achieves very high localization probability when compared with existing cluster formation algorithms, at no additional cost. Moreover, a distributed cluster formation algorithm, with no need for any centralized information exchange mechanisms, is defined.