Graphics, Figures & TablesUsing overpic in a subfigure enviroment

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
steem84
Posts: 9
Joined: Fri Dec 18, 2009 2:09 pm

Using overpic in a subfigure enviroment

Post by steem84 »

Hello,

In my thesis, I label the subfigures with the \subfigure command, in order to have nice captions with (a), (b) etc. I also know how to use the overpic command to write text over a figure.

I would like to use both commands to place text over a subfigure, however I do not know how to do that, since the figure itself is an input for both commands.

I tried the following

Code: Select all

\begin{figure}
\subfigure[first caption]{\includegraphics[width=0.98\textwidth]{Figures/figure1}}
    \begin{overpic
    \put(10,10){set}
    \end{overpic}
\subfigure[seconds caption]{\includegraphics[width=0.98\textwidth]{Figures/figure2}}
    \begin{overpic
    \put(20,20){specimen}
    \end{overpic}
\caption{caption}
\end{figure}
Obviously this does not work. Does anyone have an idea?

Thanks in advance

Recommended reading 2024:

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

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

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

Using overpic in a subfigure enviroment

Post by localghost »

You are not using overpic correctly. Take a look at the manual(s) [1].

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage[font=small,labelfont=bf,tableposition=top]{caption}
\usepackage[font=footnotesize]{subfig}
\usepackage[demo,abs]{overpic}


\begin{document}
  \begin{figure}[!ht]
    \subfloat[First caption\label{subfig-1:dummy}]{%
      \begin{overpic}[grid,width=0.45\textwidth]{Figures/figure1}
        \put(10,10){set}
      \end{overpic}
    }\hfill
    \subfloat[Second caption\label{subfig-2:dummy}]{%
      \begin{overpic}[grid,width=0.45\textwidth]{Figures/figure2}
        \put(20,20){specimen}
      \end{overpic}
    }
    \caption{Caption}\label{fig:dummy}
  \end{figure}
\end{document}
[1] View topic: Overlaying text on figure


Best regards
Thorsten¹
steem84
Posts: 9
Joined: Fri Dec 18, 2009 2:09 pm

Using overpic in a subfigure enviroment

Post by steem84 »

Hello Thorsten

Thanks for the quick reply. I changed some things and it's working for me now. I post the simplified code and the result here since I think it might help someone in the future.

However, I do have a question. For the \subfloat I have to use the subfig package, \usepackage{subfig}, and in the rest of the document I used the \subfigure command from the subfigure package, \usepackage{subfigure}. I found out that the combination of commands does not work well in the code written below. Does that mean that I just have to use the subfig package and change all \subfigures in the document to \subfloats ? Or is there a way to use both packages?

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage{subfig}
\usepackage[percent]{overpic}

\begin{document}
  \begin{figure}[!ht]
    \subfloat[First caption\label{subfig-1:dummy}]{%
      \begin{overpic}[width=0.5\textwidth]{fig1}
        \put(30,30){some text}
      \end{overpic}
    }
    \subfloat[Second caption\label{subfig-2:dummy}]{%
      \begin{overpic}[width=0.5\textwidth]{fig1}
        \put(40,40){some text again!}
      \end{overpic}
    }
    \caption{Caption}\label{fig:dummy}
  \end{figure}
\end{document}
Attachments
result.PNG
result.PNG (95.32 KiB) Viewed 15409 times
steem84
Posts: 9
Joined: Fri Dec 18, 2009 2:09 pm

Re: Using overpic in a subfigure enviroment

Post by steem84 »

ok nevermind, I found out that it is also possible to use just the subfigure package and change the \subfloat to \subfigure
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Using overpic in a subfigure enviroment

Post by localghost »

steem84 wrote:[...] However, I do have a question. For the \subfloat I have to use the subfig package, \usepackage{subfig}, and in the rest of the document I used the \subfigure command from the subfigure package, \usepackage{subfigure}. I found out that the combination of commands does not work well in the code written below. Does that mean that I just have to use the subfig package and change all \subfigures in the document to \subfloats ? Or is there a way to use both packages? [...]
Don't use the subfigure package. It is obsolete [1]. And the subfig package isn't maintained anymore but will do for now. The best is to do these modifications. Don't use both packages in the same document.

For future projects that contain sub-figures it might be better to use the subcaption package that comes with caption. It has its own manual and you can be sure that it is maintained. Its user interface is very easy to handle.

[1] View topic: Obsolete packages and document classes - Avoid usage!
steem84
Posts: 9
Joined: Fri Dec 18, 2009 2:09 pm

Re: Using overpic in a subfigure enviroment

Post by steem84 »

ok, thanks for the information
Post Reply