Raster layers can be configured to display a gradient color-ramp legend. This functionality can be leveraged to create a faux legend to accompany a vector layer. This workaround is more convoluted than the other 'insert a rectangle' workaround, but it does result in a native legend item, which might be preferable in some situations.
For starters, here is my vector point layer styled using a color ramp. This screenshot shows a simple Print Layout consisting of a map and the default legend:
Now I add a random raster file to my project. I have added a small GeoTIFF of DEM data. I then set its symbology to use the same color-ramp as the vector layer:
Next, in the Print Layout's legend's properties, I can configure the raster layer's legend item with values to make it appear to represent the vector layer:
Then after some cleanup of the legend items (deleting the items we don't want to see) I can create print layouts like the following: Including using the configuration parameter to make it a horizontal legend patch: