Autonomous underwater vehicles (AUVs) are gaining increasing attention due to their promising potential for underwater multi-agent tasks in both military and civil applications. Formation control for AUVs, as the basic problem in cooperation of multiple AUVs, is gaining increasing attention due to the unique difficulties compared with formation control for surface and aerial vehicles. In this paper, we propose a formation control algorithm for underactuated AUVs while tracking a given trajectory. The proposed strategy, which leverages a leader-follower approach, is used to reduce the complexity of the control algorithm. During the formation control process, each agent tracks the same trajectory formed by pre-set waypoints with constant surge velocity by using lower-level PID controllers. Simulations are conducted to validate the proposed formation control algorithm. The AUVs' position coordinates are fed to a distributed beamforming system to demonstrate the ability to form AUV swarm coherent beams.