Leaving aside for a moment the requirement for a constant gap between rectangles, this is the same question as this Rectangle packing around a center point
The equal gap requirement can be handled by first adding to each rectangle an extra margin all around equal to the required gap, then passing the extended rectangles to the algorithm and application I provided here https://stackoverflow.com/a/79283164/16582
Here is a screenshot of the results when the required gap is zero.