# How to compose a fixed-size image from multiple eps files

I am looking for a way to build an image by overlaying a large .eps file (A.eps) with a smaller inset (B.eps). I want the final image area to have a fixed dimensions (width=\textwidth, height=10cm).

First, A.eps needs to be scaled to the image area width (i.e. \textwidth) and positioned vertically at the bottom of the image area. The original aspect ratio of A.eps must be preserved. If the height of the scaled A.eps is less than the image area height, I want the whitespace above it preserved. If it is greater, then I want the A.eps clipped back to the top of the image area.

Second, I want to inset a much smaller graphic B.eps (without scaling) positioned so that the northeast corner of B.eps is 0.5cm south and 0.5cm to the west of the northeast corner of the image area.

Lastly, I want to do this for many files where the aspect ratio of both A.eps and B.eps change. Ideally, I want to define a command and feed the names of the images as arguments.

Ideas?

• Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Aug 3 '14 at 5:33
• Hi, Unfortunately I don't have a MWE. Nothing I have tried gets close. A combination of the picture and overpic environments gives me the correct image area, but does not clip the image nor give the ability to align B.eps correctly. So, I am looking for a strategy! – gandym Aug 3 '14 at 5:44

## 1 Answer

It is probably possible to do this without TikZ, but it is quite easy with TikZ:

\documentclass{article}
\usepackage{tikz} % tikz loads graphix

\newcommand\doubleimage[2]{%
\begin{tikzpicture}
\clip (0,0) rectangle (\textwidth,10cm);
\node [above right,inner sep=0pt,outer sep=0pt] at (0,0)
{\includegraphics[width=\textwidth]{#1}};

% Remove [width=1cm] below, it is there just to scale the images used in the example
\node [below left,inner sep=0pt,outer sep=0pt] at ([shift={(-0.5cm,-0.5cm)}]\textwidth,10cm)
{\includegraphics[width=1cm]{#2}};

% the following line is just to show the extent of the image area, it can be removed
\draw [red,thick](current bounding box.south east) rectangle (current bounding box.north west);
\end{tikzpicture}}

% adjust margins just to fit both examples on same page
% just for sake of example, of course
\usepackage[vmargin=2cm,hmargin=5cm]{geometry}

\begin{document}
\noindent\doubleimage{example-image-16x10}{example-image-a}

\vspace{1cm}

\noindent\doubleimage{example-image-10x16}{example-image-b}
\end{document}


• I fully agree with Torbjørn. I regularly write documents that have many overlapping images displayed on the page and the best way that I have found to do this is using tikz. (I used to do this with word, which was a complete nightmare!) – Andrew Aug 3 '14 at 23:26
• Thanks! This answer is perfect! But, since I use auto-pst-pdf and pdflatex I am now encountering this problem: tikz-and-auto-pst-pdf-break-ghostscript. Still looking for a way around this without changing to some other compilation method. – gandym Aug 4 '14 at 6:18