Context. The frequent presence of weak magnetic fields on the surface of spotted late-B stars with HgMn peculiarity in binary systems has been controversial during the two last decades. Recent studies of magnetic fields in these stars using the least-squares deconvolution (LSD) technique have failed to detect magnetic fields, indicating an upper limit on the longitudinal field between 8 and 15 G. In these LSD studies, assumptions were made that all spectral lines are identical in shape and can be described by a scaled mean profile. Aims. We re-analyse the available spectropolarimetric material by applying the moment technique on spectral lines of inhomogeneously distributed elements separately. Furthermore, we present new determinations of the mean longitudinal magnetic field for the HgMn star HD 65949 and the hotter analog of HgMn stars, the PGa star HD 19400, using FORS 2 installed at the VLT. We also give new measurements of the eclipsing system AR Aur with a primary star of HgMn peculiarity, which were obtained with the SOFIN spectropolarimeter installed at the Nordic Optical Telescope. Methods. We downloaded from the European Southern Observatory (ESO) archive the publically available HARPS spectra for eight HgMn stars and one normal and one superficially normal B-type star obtained in 2010. Out of this sample, three HgMn stars belong to spectroscopic double-lined systems. The application of the moment technique to the HARPS and SOFIN spectra allowed us to study the presence of the longitudinal magnetic field, the crossover effect, and quadratic magnetic fields. Results for the HgMn star HD 65949 and the PGa star HD 19400 are based on a linear regression analysis of low-resolution spectra obtained with FORS 2 in spectropolarimetric mode. Results. Our measurements of the magnetic field with the moment technique using spectral lines of several elements separately reveal the presence of a weak longitudinal magnetic field, a quadratic magnetic field, and the crossover effect on the surface of several HgMn stars as well as normal and superficially normal B-type stars. Furthermore, our analysis suggests the existence of intriguing correlations between the strength of the magnetic field, abundance anomalies, and binary properties. The results are discussed in the context of possible mechanisms responsible for the development of the element patches and complex magnetic fields on the surface of late B-type stars.