7

Say I have the following code in a document typeset with memoir:

\begin{figure}
\centering
\subbottom[]{
\label{sub1}
\includegraphics[width=0.4\linewidth]{test.png}}%
\subbottom[]{
\label{sub2}
\includegraphics[width=0.4\linewidth]{test.png}}%
\caption{\subcaptionref{sub1}: Left of the figure. \subcaptionref{sub2}: Right of the figure}
\end{figure}

which generates the following figure:

enter image description here

I would like to be able to overlay some text and mathematical formula on each of the images (with coordinates relative to each image).

I read these two posts:

I really like the solution described in the first of them, i.e. using tikz commands to overlay text and formulae.

However, the examples they provide require using a tikzpicture environment, which seems to prevent me from using \subbottom[] for subfigures in memoir.

How can I use tikzpicture and scope in combination with subbottom in memoir?

For the sake of the example, say I want to overlay the symbol $\phi$ on the center of the subfigure of the left, and the symbol $\psi$ on the center of the subfigure on the right (both inside small white boxes).

1
  • what is the problem with \subbottom and tikzpicture? I use it daily. How do you use it?
    – nickpapior
    Commented Apr 23, 2012 at 18:26

2 Answers 2

10

As you asked for a tikz way, here is one. Of course you can tidy up the code a lot and create commands and such, but the example below shows you a possible way

\documentclass{memoir}

\usepackage{graphicx}
\newsubfloat{figure}
\usepackage{tikz}

\begin{document}

\begin{figure}
\centering
\subbottom[]{%
\label{sub1}
\begin{tikzpicture}[inner sep=0pt,remember picture]
\node at (0,0) {\includegraphics[width=0.4\linewidth]{test.jpg}};
\node[fill=green!20] (a) at (1,1) {A node};
\end{tikzpicture}
}%
\subbottom[]{
\label{sub2}
\begin{tikzpicture}[inner sep=0pt,remember picture]
\node at (0,0) {\includegraphics[width=0.4\linewidth]{test.jpg}};
\node[fill=red!20] (b) at (0.5,0.5) {A node};
\end{tikzpicture}
}%
\begin{tikzpicture}[remember picture,overlay]
 \draw[->,red,very thick] (a) to[bend right] (b);
\end{tikzpicture}

\caption{\subcaptionref{sub1}: Left of the figure. \subcaptionref{sub2}: Right
of the figure}
\end{figure}

\end{document}

basically you but the picture in a node and the you can but other nodes on top. by telling tikz to remember the nodes you can later connect those nodes

enter image description here

3
  • This is great. Thanks!! When you say \node[fill=red!20], what is the number 20 for? Also, do you know how can I change the width and height of the box of the node? (without changing the text or the size of the text) Commented Apr 23, 2012 at 19:46
  • 1
    @roseck: <colour>!<num> uses the notation of xcolor. It means <num>% of colour <colour>. In this case, a fill of 20% red... which is pinkish, like uncooked sausage. green!20 is more like very old sausage.
    – Werner
    Commented Apr 23, 2012 at 19:58
  • 1
    @roseck you can increase the box of A node by saying \node[fill=green!20,inner sep=10pt]. I initially set the inner sep to 0 because I wanted to avoid extra space around the picture. You could also specify minimum width=20ptand minimum height=40pt.
    – Martin H
    Commented Apr 23, 2012 at 20:16
7

You don't really need TikZ for this. However, it does allow for more freedom and variability in terms of overlaying graphics. As-is, overlays are possible via \ooalign:

enter image description here

\documentclass{memoir}% http://ctan.org/pkg/memoir
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\newsubfloat{figure}% Allows \subbottom and \subtop in figure
\newsavebox{\myfig}
\begin{document}
\begin{figure}
  \centering
  \savebox{\myfig}{\includegraphics[width=0.4\linewidth]{tiger}}% Store image
  \subbottom[]{%
    \label{sub1}%
    \ooalign{\usebox{\myfig}\cr\hss\raisebox{\dimexpr.5\ht\myfig-.5\baselineskip}{\colorbox{white}{\Huge$\phi$}}\hss}}%
  \subbottom[]{%
    \label{sub2}%
    \usebox{\myfig}}%
  \caption{\subcaptionref{sub1}:~Left of the figure. \subcaptionref{sub2}:~Right of the figure}
\end{figure}
\end{document}

The images are set in a box (\myfig) in order to obtain the appropriate height (via \ht\myfig). \ooalign overlays the dual content (image and formula) while \raisebox moves the formula into position vertically.

See this answer for a quick course in \ooalign.

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .