Putting text on a photo in a gallery

What is the way to write a caption for each image in a gallery?
I used a text block on the image, wrote the caption in it but it doesn’t stay with the image.
When the next image is displayed the previous caption is still visible.
The same thing happens if I place the text box outside of the image just below it.

The gallery has a “label” checkbox for each slide.