Graphics, Figures & TablesOverlaying text on figure

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
masher
Posts: 9
Joined: Fri Oct 23, 2009 4:24 am

Overlaying text on figure

Post by masher »

Hi all

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

\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}
I have an image that I resize, I'm then trying to use \put to place my text in the top right corner of the image.

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?
Last edited by masher on Wed Nov 04, 2009 2:09 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Overlaying text on figure

Post by localghost »

masher wrote:[...]

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?
All these questions are answered by the overpic package. The manual explains everything in detail.


Best regards
Thorsten
masher
Posts: 9
Joined: Fri Oct 23, 2009 4:24 am

Re: Overlaying text on figure

Post by masher »

Definately looks like what I want; I'll try it out at work tomorrow.

.

Incidentally, how do you find out about these packages? Is it just a matter of knowing them? None of my searching brought up anything to do with it...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Overlaying text on figure

Post by localghost »

masher wrote:[...] Incidentally, how do you find out about these packages? Is it just a matter of knowing them? None of my searching brought up anything to do with it...
All the packages can be found on CTAN. But it's also a little bit of knowledge and experience.
masher
Posts: 9
Joined: Fri Oct 23, 2009 4:24 am

Overlaying text on figure

Post by masher »

localghost wrote: The manual explains everything in detail.
We must have different definitions of "in detail"!

.

This package could be a lot more useful if it set each side of the image to go from 0-100% in relative mode, rather than give the longest side 0-100 and label the other side up to 70% or however long it is. If that was done, then \put(50,50) would put the object in the middle of the image...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Overlaying text on figure

Post by localghost »

masher wrote:We must have different definitions of "in detail"! [...]
In this case you are right. These two papers aren't much more than an overview. Usually manuals are much more comprehensive. But it's enough for handling the package.
Post Reply