Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have two PDF figures (charts) in a LaTeX document. As one of them is really simple, and I have some document space constraints, I was thinking of putting it in the upper right corner of the second chart.

I could do this using some image editing tool. But can I do it directly in LaTeX (avoiding the need to create a single merged PDF)?

share|improve this question
1  
You could simply use a picture environment and place both images with \put. –  Stephan Lehmke Jul 3 '12 at 13:14
    
@Stephan: would you mind giving an example, as I can't find how to include figure (environments) in a picture environment? For example, this link (ursoswald.ch/LaTeXGraphics/picture/picture.html) doesn't talk about it, as doesn't the picture package documentation. –  Rabarberski Jul 3 '12 at 13:38
1  
You don't need to use the figure environment to use \includegraphics. Place the whole picture environment in a single figure environment if you want it to float. –  Ian Thompson Jul 3 '12 at 13:52
    
\includegraphics[height=4cm]{chart1.pdf}\llap{\raisebox{2cm}{\includegraphics[h‌​eight=2cm]{chart2.pdf}}}. You might have to play a bit with the numbers, height of chart2 + raise = height of chart1. –  Daniel Jul 3 '12 at 13:54

2 Answers 2

up vote 12 down vote accepted

Typesetting material over each other is relatively easy without any extra packages by exploiting the \llap and \rlap TeX commands. These basically typeset some material from the current position to the left, respectively right, regardless what and without changing the current position.

As graphics included by \includegraphics are aligned at the bottom, one additionally can use \raisebox to lift the second graphics in y direction:

\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}

\begin{document}
  \lipsum[3]
  \begin{figure}
    \centering
    \includegraphics[height=6cm]{example-image-a}%
    \llap{\raisebox{3cm}{%  move next graphics to top right corner
      \includegraphics[height=3cm]{example-image-b}%
    }}
    \caption{My overlay figure.}
  \end{figure}  

  \lipsum[3]

\end{document}

enter image description here

If one does not want to scale the first figure to a specific height, but to something like \columnwidth, it is also possible to measure the resulting height. There are many ways to do this (which basically all results in: "box it" + "measure it") In the following, I simply use the functionality provided by the calc package:

\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{calc}       % for height measuring

\begin{document}
  \lipsum[3]
  \begin{figure}
    \centering
    % first measure it's height (store in \dimen0), then actually include the graphics
    \settototalheight{\dimen0}{\includegraphics[width=\columnwidth]{example-image-a}}%
    \includegraphics[width=\columnwidth]{example-image-a}%
    \llap{\raisebox{\dimen0-3cm}{%  move next graphics to top right corner
      \includegraphics[height=3cm]{example-image-b}%
    }}
    \caption{My overlay figure.}
  \end{figure}  

  \lipsum[3]

\end{document}

enter image description here

share|improve this answer
    
Thanks for the very clear example. Unfortunately, seems like I do have to specify the height of the first figure (like you did with height=6cm), as when using width=\columnwidth instead, the positioning gets messed up. –  Rabarberski Jul 4 '12 at 7:43
1  
@Rabarberski: It's possible to automatically determine the height. See updated answer. –  Daniel Jul 4 '12 at 8:43
    
Where are the background lines in your last image? –  stalking is prohibited Jul 4 '12 at 9:09
    
@Daniel: thanks for your efforts! –  Rabarberski Jul 4 '12 at 11:50
    
@Forgiver: In the PDF they are still there, just have been "optimized" away in the PDF->GIF conversion for the screenshot. –  Daniel Jul 4 '12 at 12:35

It is a generic solution. With a trivial edit you will get what you want. Please TeXing it with either xelatex or latex-dvips-ps2pdf.

enter image description here

\documentclass{article}
\usepackage{graphicx}
\usepackage{pstricks}

\newbox\IBox
\savebox\IBox{\includegraphics[scale=0.8]{god}}

\def\Rows{5}
\def\Columns{5}

\psset
{
    xunit=\dimexpr\wd\IBox/\Columns\relax,
    yunit=\dimexpr\ht\IBox/\Rows\relax,
}

\usepackage{lipsum}
\begin{document}
\lipsum[1-3]
\begin{figure}
\begin{pspicture}[showgrid=top](\dimexpr\wd\IBox+3\psxunit\relax,\ht\IBox)
    \rput[bl](0,0){\usebox\IBox}
    \rput[tr](8,5){\includegraphics[scale=0.5]{example-image-b}}
\end{pspicture}
\caption{The Gods must be crazy.}%
\label{fig:}%
\end{figure}
\lipsum[4-7]
\end{document}

The image is taken from The Gods must be crazy.


Hopefully it is the last edit.

enter image description here

\documentclass{article}
\usepackage{graphicx}
\usepackage{pstricks}

\newbox\IBox
\savebox\IBox{\includegraphics[scale=1]{example-image-a}}

\def\Rows{5}
\def\Columns{5}

\psset
{
    xunit=\dimexpr\wd\IBox/\Columns\relax,
    yunit=\dimexpr\ht\IBox/\Rows\relax,
}

\usepackage{lipsum}
\begin{document}
\lipsum[1-3]
\begin{figure}
\begin{pspicture}[showgrid=top](\wd\IBox,\ht\IBox)
    \rput[bl](0,0){\usebox\IBox}
    \rput[tr](\wd\IBox,\ht\IBox){\includegraphics[scale=0.5]{example-image-b}}
\end{pspicture}
\caption{Is the answer of this question ``No''?}%
\label{fig:}%
\end{figure}
\lipsum[4-7]
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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