On the scale of galactic haloes, the distribution of matter in the cosmos is affected by energetic, non-gravitational processes, the so-called baryonic feedback. A lack of knowledge about the details of how feedback processes redistribute matter is a source of uncertainty for weak-lensing surveys, which accurately probe the clustering of matter in the Universe over a wide range of scales. We developed a cosmology-dependent model for the matter distribution that simultaneously accounts for the clustering of dark matter, gas, and stars. We informed our model by comparing it to power spectra measured from the BAHAMAS suite of hydrodynamical simulations. In addition to considering matter power spectra, we also considered spectra involving the electron-pressure field, which directly relates to the thermal Sunyaev-Zel’dovich (tSZ) effect. We fitted parameters in our model so that it can simultaneously model both matter and pressure data and such that the distribution of gas as inferred from tSZ has an influence on the matter spectrum predicted by our model. We present two variants, one that matches the feedback-induced suppression seen in the matter–matter power spectrum at the percent level and a second that matches the matter–matter data to a slightly lesser degree (≃2%). However, the latter is able to simultaneously model the matter–electron pressure spectrum at the ≃15% level. We envisage our models being used to simultaneously learn about cosmological parameters and the strength of baryonic feedback using a combination of tSZ and lensing auto- and cross-correlation data.