Update 3
This is the last revision, I promise.
The only change is the use of pgfmath.sty
in place of fp-eval.sty
which, in turn, required a little special handling to avoid dimension too large
errors. As well, the use of pgfmath.sty
allowed for considerable simplification. The new output is identical to the old.
%===8><-----%
I was unhappy with the way that I left the \scaletoarea macro. It has been altered to be, hopefully, a little more user-friendly. I have made it possible to use the options to \includegraphics
for all of the macros. Take a look at the examples.
%===8><---%
I take it that you want all of the graphics to have the same area regardless of the aspect ratio. The following code does that.
There are two approaches outlined here.
The first scales subsequent graphics based on the size of the first graphic Use \fpic
for the first graphic; using \spic
for the subsequent graphics will size them to have the same area as the first graphic. Use the options to \fpic
(the same as those to \includegraphics
) to size the first graphic accordingly.
Second, if you know the target area, you can use \scaletoarea{<unitless area>}{<linear unit of area>}{<name of graphic>}
. For example, if you were to scale a graphic, foo
, so that it is 5 square inches in area, you would write: \scaletoarea{5}{in}{foo}
. Any of the units recognized by TeX can be used.
\documentclass{article}
\usepackage{graphicx,calc,pgfmath}
\usepackage[margin=0.5in]{geometry}
\newlength\fpicw
\newlength\fpich
\newlength\spicw
\newlength\spich
\newsavebox{\firstpic}
\newsavebox{\nextpics}
\newlength{\targetarea}
%% \fpic[<options to \includegraphics>]{<name of graphic>}
\newcommand{\fpic}[2][]{% First picture, use \includegraphics, and options
\sbox{\firstpic}{\includegraphics[#1]{#2}}%
\settoheight{\fpich}{\usebox{\firstpic}}%
\settowidth{\fpicw}{\usebox{\firstpic}}%
\usebox{\firstpic}%
}
%% \spic[<options to \includegraphics>]{<graphic name>}
\newcommand{\spic}[2][]{% Second and succeeding pictures
\sbox{\nextpics}{\includegraphics[#1]{#2}}%
\settoheight{\spich}{\usebox{\nextpics}}%
\settowidth{\spicw}{\usebox{\nextpics}}%
\pgfmathsetmacro{\scaling}{sqrt((\fpicw/\spicw)*(\fpich/\spich))}%
\scalebox{\scaling}{\usebox{\nextpics}}%
\typeout{**The scaling (#2) = \scaling}% Comment-out if not needed
}
%% \scaletoarea[<options to \includegraphics>]{<unitless area>}{<unit of area (linear)>}{<graphic name>}
\newcommand{\scaletoarea}[4][]{%
\pgfmathsetmacro{\mytmp}{sqrt(#2)}%
\setlength{\targetarea}{\mytmp #3}%
\sbox{\nextpics}{\includegraphics[#1]{#4}}%
\settoheight{\spich}{\usebox{\nextpics}}%
\settowidth{\spicw}{\usebox{\nextpics}}%
\pgfmathsetmacro{\scaling}{sqrt((\targetarea/\spicw)*(\targetarea/\spich))}%
\scalebox{\scaling}{\usebox{\nextpics}}%
\typeout{++The scaling (#4) = \scaling}% Comment-out if not needed
}
%% \scaletoareab[<options to \includegraphics>]{<square root of desired area>}{<name of graphic>}
\newcommand{\scaletoareab}[3][]{%
\setlength{\targetarea}{#2}%
\sbox{\nextpics}{\includegraphics[#1]{#3}}%
\settoheight{\spich}{\usebox{\nextpics}}%
\settowidth{\spicw}{\usebox{\nextpics}}%
\pgfmathsetmacro{\scaling}{sqrt((\targetarea/\spicw)*(\targetarea/\spich))}%
\scalebox{\scaling}{\usebox{\nextpics}}%
\message{++The scaling (#3) = \number\scaling}%
}
\begin{document}
\fpic[width=1.25in]{Peppers}\spic{Pasta}\spic{OldImage}\spic{BethanyDrawing}
\scaletoarea{3}{in}{Peppers}\scaletoarea{12}{cm}{Pasta}\scaletoarea{2}{in}{OldImage}\scaletoarea{61}{pc}{BethanyDrawing}
\scaletoarea[width=0.5in,height=3in,keepaspectratio=false]{3}{in}{Peppers}
\scaletoareab[width=0.5in,height=3in,keepaspectratio=false]{1.732050807568877in}{Peppers}
\end{document}
