5

I'm using the overpic package in the memoir class to include figures and superimpose text on them. Is there a simple way to tell overpic to use a different font than the main font of my text? (I still want the figure captions to be in the main font, though.)

Here's a MWE:

\documentclass[11pt,a4paper]{memoir}

\usepackage{fouriernc} % use the Arev font
\usepackage{overpic} % use the overpic package

% caption images outside the figure environment
\newfixedcaption{\figcaption}{figure} \captionnamefont{\normalfont} \captiontitlefont{\normalfont}

\begin{document}

This is the font of my main text.

\begin{center}
\begin{overpic}[width=0.5\textwidth]{./myfig.pdf}
\put(10, 10){This should be a different font}
\end{overpic}
\figcaption{This should be the same font as my main text.}
\end{center}

\end{document}
  • 1
    Just say, for instance, \put(10,10){\sffamily This is in the sans serif font}; edit your question if this isn't what you have in mind. – egreg Feb 17 '12 at 22:10
  • This is exactly what I had in mind, but is there a way to define a macro so that every \put command in overpic automatically switches to some font? (So that I don't need to write something like \sffamily in every \put in the document...) Thanks! – jamaicanworm Feb 18 '12 at 2:23
  • 1
    \usepackage{etoolbox} and then \AtBeginEnvironment{overpic}{\sffamily} should work. – egreg Feb 18 '12 at 9:56
4

You could redefine \put to insert \sffamily (or whichever font selection) automatically by inserting the following in your document preamble:

\let\oldput\put
\def\put(#1,#2)#3{%
  \oldput(#1,#2){\sffamily #3}%
}

Here's a minimal example:

enter image description here

\documentclass[11pt,a4paper]{memoir}
\let\oldput\put
\def\put(#1,#2)#3{%
  \oldput(#1,#2){\sffamily #3}%
}
\usepackage{fouriernc} % use the Arev font
\usepackage{overpic} % use the overpic package

% caption images outside the figure environment
\newfixedcaption{\figcaption}{figure} \captionnamefont{\normalfont} \captiontitlefont{\normalfont}

\begin{document}

This is the font of my main text.

\begin{center}
\begin{overpic}[width=0.5\textwidth]{tiger.pdf}
\put(10, 10){This should be a different font}
\end{overpic}
\figcaption{This should be the same font as my main text.}
\end{center}

\end{document}
  • Thanks! In my actual document, though, most of the text in \puts is actually in math mode (inside $s), so the sffamily font doesn't help distinguish it... Is there another font I can use with a different math mode font than Arev? – jamaicanworm Feb 18 '12 at 16:35
  • 1
    @jamaicanworm: Do you have a variety of serif and sans-serif math fonts going on in your document? If not, the sfmath package (or sansmath) might be of help. – Werner Feb 18 '12 at 16:43
  • I added \usepackage{sansmath} to the top of the document, and replaced \sffamily with \sansmath, and it's working great now! – jamaicanworm Feb 18 '12 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.