Differential production cross sections of J/$\psi$ and $\psi$(2S) charmonium and $\Upsilon$(nS) (n = 1, 2, 3) bottomonium states are measured in proton-proton collisions at $\sqrt{s} =$ 13 TeV, with data collected by the CMS detector at the LHC, corresponding to an integrated luminosity of 2.3 fb$^{-1}$ for the J/$\psi$ and 2.7 fb$^{-1}$ for the other mesons. The five quarkonium states are reconstructed in the dimuon decay channel, for dimuon rapidity $|y| <$ 1.2. The double-differential cross sections for each state are measured as a function of $y$ and transverse momentum, and compared to theoretical expectations. In addition, ratios are presented of cross sections for prompt $\psi$(2S) to J/$\psi$, $\Upsilon$(2S) to $\Upsilon$(1S), and $\Upsilon$(3S) to $\Upsilon$(1S) production.
The ratios of the production cross sections between the excited $\Upsilon$(2S) and $\Upsilon$(3S) mesons and the $\Upsilon$(1S) ground state, detected via their decay into two muons, are studied as a function of the number of charged particles in the event. The data are from proton-proton collisions at $\sqrt{s} =$ 7 TeV, corresponding to an integrated luminosity of 4.8 fb$^{-1}$, collected with the CMS detector at the LHC. Evidence of a decrease in these ratios as a function of the particle multiplicity is observed, more pronounced at low transverse momentum $p_\mathrm{T}^{\mu\mu}$. For $\Upsilon$(nS) mesons with $p_\mathrm{T}^{\mu\mu}$ $\gt$ 7 GeV, where most of the data were collected, the correlation with multiplicity is studied as a function of the underlying event transverse sphericity and the number of particles in a cone around the $\Upsilon$(nS) direction. The ratios are found to be multiplicity independent for jet-like events. The mean $p_\mathrm{T}^{\mu\mu}$ values for the $\Upsilon$(nS) states as a function of particle multiplicity are also measured and found to grow more steeply as their mass increases.