The square wave is frequently used as the transmitter waveform in marine controlled-source electromagnetics (CSEM) surveys. This waveform has the advantage of transferring maximum energy to the subsurface because the transmitter current is running at its peak amplitude at all times. However, a limitation of the square wave is that most of the transmitted energy is in the first harmonic. Processing methods such as depth migration and inversion have shown improved results if a transmitter waveform with substantial amounts of energy at multiple frequencies is used. We propose a method for designing transmitter waveforms where current amplitudes as a function of frequency can have an approximate predefined or desired distribution. At the same time, we require that the transmitter operate at its peak current at all times to maximize the energy transferred to the subsurface. To obtain the desired current spectra, the number of switching times in a period is allowed to be larger than two, which is the number of switching times per period for a standard square wave. The method is based on matching the desired frequency spectra with the spectra obtained from these generalized square waves. This optimization problem is solved by a Monte Carlo method. The resultant waveforms can be used for an electric-dipole transmitter.