If the five images have the same aspect ratio, it's not difficult to solve the problem: let's say that the rectangles have base a and height a/r (with possibly different a each). Let's say we want to leave 12pt of blank space between the two halves and 3pt of space between the small figures.
We have thus to compute dimensions x and y, the bases of the big rectangle and of the small ones respectively, such that
x + 2y = \textwidth
-12pt-3pt
x/r = 2y/r + 3pt
A bit of linear algebra will tell that
x = (\textwidth - 15pt + 3ptr)/2
y = (\textwidth - 15pt - 3ptr)/4
Let's say that r=2; then
\documentclass[a4paper]{article}
\usepackage{graphicx,subfig}
\begin{document}
\begin{figure}
\centering
\subfloat[]{\includegraphics[width=\dimexpr(\textwidth-15pt+3pt*2)/2\relax]{fig1}}%
\hfill
\subfloat[]{\vbox{\offinterlineskip\halign{#\hskip3pt&#\cr
\includegraphics[width=\dimexpr(\textwidth-15pt-3pt*2)/4\relax]{fig2}&
\includegraphics[width=\dimexpr(\textwidth-15pt-3pt*2)/4\relax]{fig3}\cr
\noalign{\vskip3pt}
\includegraphics[width=\dimexpr(\textwidth-15pt-3pt*2)/4\relax]{fig4}&
\includegraphics[width=\dimexpr(\textwidth-15pt-3pt*2)/4\relax]{fig5}\cr
}}}
\caption{Test images}
\end{figure}
\end{document}
If the package subcaption is used instead of subfig, change \subfloat[]
into \subcaptionbox{}
(thanks to Axel Sommerfeldt).
I've used \halign
to get a more precise control on the spacing.
If the figure on the left has a different aspect ratio than the ones on the right, it's not difficult either.
\halign
is the TeX primitive on which tabular
is built. There's too much to say about it; the main thing is the structure:
\halign{<template1>&<template2>&...\cr
<body>
}
The tokens up to the first \cr
define the templates for the columns; each is separated from the following by &
. A template consists of three parts:
<before>#<after>
<before>
means tokens that are inserted at the start of each cell, #
stands for the actual cell entry in the body, and similarly <after>
means tokens that are inserted after the entry. For example a template for "centered cells" is
\hfil#\hfil
In our case the templates are trivial: #\hskip3pt
and #
; since all images will have the same width it's not necessary to specify anything else.
Notice that \halign
, by default, doesn't insert intercolumn space; to be precise it inserts \tabalign
glue, but talking about this would take too far away. The default value of the parameter is zero, anyway.
<body>
is similar to the body of a tabular
environment, but rows must be terminated by \cr
and spaces before &
and \cr
are not ignored; those after them are. Also the final row must be terminated by \cr
.
Between rows one can specify spacing (and other things) via \noalign
.
To get precise control on spacing, I've said \offinterlineskip
before \halign
so that TeX will butt all rows together without interline glue. LaTeX does the same, actually. This is done inside a \vbox
, so that the setting will be in force only there.
It is clearly a bug in the driver for package graphicx
:
pdftex.def
: ok.
dvips.def
: ok for PostScript images, but clipping is not supported for bitmap images.
xetex.def
: Clipping is not supported at all.
dvipdfm.def
: The image is not trimmed, but distorted in the final area.
dvipdfmx.def
: The whole image is put in the final area without distortion, but
empty space is put above the small image.
A remark to keepaspectratio
: It has a meaning only if both the width
and
height
are specified. Thus the setting and values of keepaspectratio
does not matter here.
There is a solution for dvips.def
, dvipdfm.def
and dvipdfmx.def
if pdfTeX
is used as TeX compiler (for DVI mode). Package bmpsize
fixes as side effect the
defective drivers. And the package improves the bitmap inclusion making separate bounding box files obsolete. The driver xetex.def
cannot be fixed this way, because XeTeX misses
primitives from pdfTeX (especially \pdffiledump
), needed by bmpsize
.
\usepackage[dvipdfm]{graphicx}
\usepackage{bmpsize}
Best Answer
(Summarising the comments as an answer.)
pdfTeX will work with
px
units, but you have to set these up appropriately using\pdfpxdimen
. This is the physical width of one pixel, and has default value of1 bp
, meaning that images initially are assumed to be 72 dpi.\pdfpxdimen
is a low-level dimen primitive, and so is best set using\dimexpr
:where
<dpi>
is the resolution of the image.With that set correctly, you can then use
\includegraphics
as normal, addingpx
to the values used by thetrim
(or other) key to get the right result.As an example, consider the two images
and
which have the same pixel size but different resolution. Using the LaTeX file
results in the output file
which shows the result of the trimming - both are the same. (I've scaled the second image so that the two are printed the same size by pdfTeX.)