[texhax] sidecap + wrap
Tim Holy
holy at wustl.edu
Fri Oct 17 00:35:45 CEST 2008
Hello,
I've been a LaTeX user for some time, but have never delved into hacking it
before, and I'm quite a novice; please pardon my ignorance.
I'm writing a grant application with very limited space. To help save space, I
want the figure captions to be as space efficient as possible. Since my
captions tend to be long (they explain a lot of details about the figures),
what I want is something like "sidecap", but that when the caption reaches
the bottom of the figure, it then fills the entire available width.
Schematically, if "F" indicates region occupied by figure, and "C" indicates
region occupied by caption, then standard figures are like this:
FFFFF
FFFFF
FFFFF
CCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCC
(this email may be best viewed with a fixed-width font!) and sidecap gives you
figures like this:
CCCCCCCCCCCCCCC
CCCCCCCCCCCCCCC
CCCCCCCCCCCCCCC
FFFFF CCCCCCCCCCCCCCC
FFFFF CCCCCCCCCCCCCCC
FFFFF CCCCCCCCCCCCC
(notice the blank space above the figure, because the caption is bigger than
the figure) and what I want is this:
FFFFF CCCCCCCCCCCCCCC
FFFFF CCCCCCCCCCCCCCC
FFFFF CCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCC
It turns out that this effect isn't too hard to achieve, but the way I've done
it requires a lot of manual tweaking; I can't help but think that there must
be a better way.
Here's the really awful manual method:
\documentclass{article}
\usepackage{graphicx}
\newcount\thisfigindentedlines
\newlength{\thisfigurewidth}
\newlength{\thiscaptionindent}
\newlength{\thisremaininglength}
\newlength{\captionsep}
\setlength{\captionsep}{0.15in}
\newlength{\extravspace}
\setlength{\extravspace}{-0.25in}
\newcommand{\setcaptionlengths}{
\setlength{\thiscaptionindent}{\thisfigurewidth}
\addtolength{\thiscaptionindent}{\captionsep}
\setlength{\thisremaininglength}{\columnwidth}
\addtolength{\thisremaininglength}{-\thiscaptionindent}
}
\begin{document}
This is a test document to see if I can develop a version of side-captioning
that wraps any extra text around the bottom of a figure.
\def\thisfigureheight{1.25in}
\setlength{\thisfigurewidth}{3.5in}
\setcaptionlengths
\begin{figure}
\includegraphics[height=\thisfigureheight]{gull}\quad
\includegraphics[height=\thisfigureheight]{tiger}
\vspace{-\thisfigureheight}
\vspace{\extravspace}
\caption{
\parshape=10 \thiscaptionindent \thisremaininglength \thiscaptionindent
\thisremaininglength \thiscaptionindent \thisremaininglength
\thiscaptionindent \thisremaininglength \thiscaptionindent
\thisremaininglength \thiscaptionindent \thisremaininglength
\thiscaptionindent \thisremaininglength \thiscaptionindent
\thisremaininglength \thiscaptionindent \thisremaininglength 0pt \columnwidth
({\bf A}) A gull. This is a bird. It's a sea bird. You know, one that flies
out over the ocean. I don't know much about gulls, so I don't know what more
to say about them. {\bf B} A tiger. They're big. I hear they're friendly, at
least when they don't intend to eat you. Certainly, they're really strong.
They like water.
}
\end{figure}
\end{document}
Note the many ways that this solution could be improved:
1. I use the \parshape command with an explicit number of indented lines; but
this seems silly, because I already have a variable that contains the height
of the figure. It seems that I should be able to calculate the number of
lines (from \thisfigureheight and \baselineskip) and then put this in a loop.
But I'm not having any luck with a construct like this:
\def\parshapecmd{}
\loop\ifnum\thisfigindentedlines>1
\advance\thisfigindentedlines by -1
\def\parshapecmd{\parshapecmd \thiscaptionindent \thisremaininglength}
\repeat
\def\parshapecmd{\parshapecmd 0pt \columnwidth}
I just don't know enough TeX to know what's wrong with it.
2. At the end of the \includegraphics commands, it seems that there should be
some way of knowing "where you are" (i.e., where the "cursor" is) so that you
know both the height and width of the inserted graphics. That way, the user
doesn't have to explicitly specify widths and heights.
I'm envisioning that this should be as easy as:
\def\thisfigureheight{1.25in} % needed only because there are 2 images
\begin{figure}
\includegraphics[height=\thisfigureheight]{gull}\quad
\includegraphics[height=\thisfigureheight]{tiger}
\sidecapwrap{
({\bf A}) A gull....
}
\end{figure}
Can anyone offer advice?
Thanks,
--Tim
More information about the texhax
mailing list