In this paper, we extend a famous motion planning approach GPMP2 to work with multiple robots in formation, yielding a novel centralized trajectory generation method for the multi-robot formation. A sparse Gaussian Process model is employed to represent the continuous-time trajectories of all robots as a limited number of states, which brings high computational efficiency due to the sparsity. We add constraints to guarantee collision avoidance between individuals and formation maintenance, then all constraints and kinematics are formulated on a factor graph. By introducing a global planner, our proposed method can generate trajectories efficiently for adaptive formation change of multiple quadrotors which have to get through a width-varying area. Finally, we provide the implementation of an incremental replanning algorithm to demonstrate the online operation potential of our proposed framework. The experiments in simulation and real world illustrate the feasibility, efficiency and scalability of our approach.