The two answers above are correct, but I want to make it more generic; this can be applied to anything with multiple elements over a distance. For example, this could also be used for spacing stile rails for a deck railing system, etc ...
T = total distance to be covered
C = component width
S = desired spacing in between components
Q = quantity of components
Hence:
T = (C + S) x Q
* Algebraically, this can be solved for any one unknown element when the other elements are known ...
* Often, the result will not be a whole number. You'll have to round up/down by one component to make it work. The larger the component is relative to the spacing, the more "adjustment" you have to make. When the component is very small relative to the spacing, it's very difficult for the eye to notice at a glance.
* Always make sure the units of measure are the same; inches to inches, cm to cm, etc ...
* The formula above presumes only one type of component, all of the same width. If you have components of varying widths, the formula becomes more complicated and then depends if you want to defer to equal spacing between components, or equal component centerline spacing ...