Graphics, Figures & Tablesfloat a caption on top of image

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
CoolnessItself
Posts: 47
Joined: Wed Nov 11, 2009 9:30 pm

float a caption on top of image

Post by CoolnessItself »

I have a figure with includegraphics. I'm trying to inset some text ON TOP of the figure, either with absolute positioning to the page, or ideally, relative to some corner of the figure. But in any case, it needs to go on top, not next to or below.
Maybe I'm searching for the wrong thing, but everything I've tried so far results in text to the side.
For example,

Code: Select all

\begin{center}
  \includegraphics[scale=1.0]{myfig.eps}
\begin{picture}(-10,-30)(1,1)
\setlength\fboxsep{10pt}\fbox{\begin{centering}Some text!\end{centering}}
\end{picture}
\end{center}
Suggestions? I guess what I'm looking for is a "legend" of sorts

Recommended reading 2024:

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

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

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

float a caption on top of image

Post by gmedina »

Hi,

why do you use a picture environment? You could simply try something like the following:

Code: Select all

\documentclass{article}
\usepackage[demo]{graphicx}

\begin{document}

\noindent\begin{minipage}{\textwidth}  
  \centering
 \setlength\fboxsep{10pt}\fbox{\centering Some text!}\\[3pt]
  \includegraphics[scale=1.0]{myfig.eps}
\end{minipage}

\end{document}
Note that I used a minipage environment to keep the text and the figure together. I used the demo option for graphicx to make my code compilable for everyone; don't forget to delete it in your actual code.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
CoolnessItself
Posts: 47
Joined: Wed Nov 11, 2009 9:30 pm

float a caption on top of image

Post by CoolnessItself »

Perhaps I wasn't clear enough.
I attached an image of what your code does vs what I'm hoping to achieve. Is something like this possible?


Edit by localghost: No external links! Attachments go onto the forum server.
Attachments
captionfloat.png
captionfloat.png (4.11 KiB) Viewed 2558 times
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

float a caption on top of image

Post by gmedina »

Yes, it is possible and you can do it in sveral ways; one possibility would be to use the textpos package that allows you to add material in absolute positions on the page.

Edit: another option could be the overpic package.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply