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:
[![enter image description here][1]][1]

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:
[![enter image description here][2]][2]

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:
[![enter image description here][3]][3]

Then I clean up the legend items, renaming the raster layer's entry in the legend, removing the *Band 1* sub-title, and removing the *My Vector Layer* legend item.
[![enter image description here][4]][4]

This results in a print layout like the following. Note that I have hidden the bogus raster file from the project:

[![enter image description here][5]][5]

I can also use the *Orientation* parameter to make it a horizontal legend patch:
[![enter image description here][6]][6]


  [1]: https://i.sstatic.net/SKsA5.png
  [2]: https://i.sstatic.net/AnLkX.png
  [3]: https://i.sstatic.net/AaNKJ.png
  [4]: https://i.sstatic.net/L1H4m.png
  [5]: https://i.sstatic.net/eSY84.png
  [6]: https://i.sstatic.net/FAITR.png