How can excitation be used of an alternator to control the power factor?
The excitation current supplied to a wound-field synchronous generator (WFSG)(alternator) determines the leading or lagging reactive volt-amperes that the generator can supply while operating at a given voltage.

Here are three possible operating conditions:

For a system with just a generator and a load, the excitation is used to maintain the generator voltage at the desired level by matching the reactive volt-ampere requirement of the load. The generator power factor will inherently match the load power factor, but if the load power factor changes, the voltage will change unless the generator excitation is adjusted.

For a system with multiple generators feeding a grid, all generators will inherently operate at the grid voltage and power factor. The excitation of each individual generator can be adjusted to supply a lower or higher share of real power and reactive volt-amperes.  Real power is increased or decreased by increasing or decreasing the driving torque of the prime mover. Reactive volt-amperes is adjusted by adjusting the generator excitation.

A WFSG can also be operated as a capacitor to increase the power factor of a load that has a lagging power factor. In that case, the WFSG supplies only reactive volt-amperes while real power is supplied by the grid through one or more other generators.