[Tex/LaTex] Place text on lower right corner of picture


I am trying to place some text (a credit-line) on the lower right corner of (many) pictures. The text should be right-aligned with the right edge of the picture. I tried things like



        \put (98,2) {\makebox(0,0)[r]{\footnotesize some text}}%


where #1 is the filename of the figure.
This seems to work if the the picture has landscape format. If it is in portrait the text appears outside on the right. It seems that the coordinates used by put are the same in x- and y-direction and determined by the larger of the dimensions of the images.
Is there a way to correctly right justify the text with the right edge of the pictures?

Best Answer

I see no need for extra packages in this case (if I understand the question). You can use just

\includegraphics[width=5cm]{example-image-a}% <--important!
\makebox[0pt][r]{\footnotesize some text}

The comment sign is important in order to avoid spurious space. A little \raisebox may be helpful. So e.g. the following code




\makebox[0pt][r]{\footnotesize some text}

\raisebox{1pt}{\makebox[0pt][r]{\footnotesize some other text}}


generates enter image description here