I am trying to overlay some text on the top right corner of an image.
The way that I am currently tackling the problem is as follows:
Code: Select all
Code, edit and compile here:
\documentclass{report}\usepackage{graphicx,color,layout}\begin{document}\begin{figure}%I scale all images to give me a consistent final size% They each do not necessarily have the same number of pixels\resizebox{0.7\textwidth}{!}{{\textcolor{red}{\rule{4cm}{3cm}}}}%I'm using a \rule instead of my real image% I got -241.5 from looking at the \layout and multiplying the textwidth by 0.7% 169 came from trial and error\put (-241.5, 169){\makebox[0.7\textwidth][r]{My text }}%I want the text to go in the top right corner\end{figure}%\layout\end{document}
Is there anyway that I can get the dimensions of the image so I can feed them into the \put as coordinates so I can automatically position my text? Currently, I'm using a \makebox that is the sasme width as the image with right aligned text in it. I'm manually calculating the \put x-coord and getting the y-coord by trial and error. I would like to generalise this to figures of any size and aspect ratio. It would be nice if it doesn't break when I change either the \resize or the \textwidth...
Questions:
Are there any pre-made packages that can do this?
Is there a better way of doing this?
Can I get the dimensions of the image to put into the \put as coordinates to automatically position my text?