Sie sind hier

Figure/Table Captions in the Margin?

Hi All..

I've been struggeling some time now trying to find out how to get the captions of my figures and tables next to the floats in the margin. I'd like the captions to be on the outer margin of the page, aligned either to the top or bottom of the float (adjustable would be nice, though).

Somehow the very few examples I've come across so far don't seem to work and I'd rather write .tex than .cls files ;-)

I hope that someone can help me on that one. (btw, I'm using the scrbook class with pdftex..)

thanks in advance,
jens

KOMA script environment captionbeside provides a lot of the functionality that is needed to achive this. You just have to set its width to \linewidth+marginparsep+marginparwidth and occupy \linewidth with your figure or table. The rest \marginparsep+\marginparwidth is then used for a small horizontal skip and caption. The captionbeside environment is aligned horizontally using the starred version of its last optional parameter.

There are several draw backs in the code below:

1. As horizontal skip inserted between figure content and caption and \marginparsep seem to be equally large here (1em?) I ignored both in the code.

2. As I don't know how to provide multiple optional parameters I
didn't provide one to adjust figure alignment. Content is hardcoded to be centered, but can be aligned differently using a \parbox manually.

3. Caption alignment is hardcoded to be \raggedright on both even and odd pages. There is no option to control this behaviour currently. If you want to use \RaggedRight from the ragged2e package (to allow for hyphenation) or want a \raggedleft alignment on even pages you have to change the code.

Markus, as I think this environment is quite usefull, could the piece of code below be a starting point for a new KOMA script feature?

Regards,
Stephan Hennig

\documentclass{scrbook}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{ifthen}

%provide \margincap command
\makeatletter
\newsavebox{\mcap@figbox}
\newlength{\mcap@capbesidewidth}
\newcommand{\margincap}[3][]{%
%save content in a box
\sbox{\mcap@figbox}{#3}%
%calculate total width used by figure and caption
\setlength{\mcap@capbesidewidth}{\linewidth}%
\addtolength{\mcap@capbesidewidth}{\marginparsep}%
\addtolength{\mcap@capbesidewidth}{\marginparwidth}%
%call captionbeside environment
%with or without optional argument
\ifthenelse{\equal{#1}{}}{%
\begin{captionbeside}[#2]{%
\raggedright #2}[o][\mcap@capbesidewidth][0pt]*%
}{%
\begin{captionbeside}[#1]{%
\raggedright #2}[o][\mcap@capbesidewidth][0pt]*%
}%
%write figure horizontally centered
\makebox[\linewidth][c]{\usebox{\mcap@figbox}}%
%end environment
\end{captionbeside}%
}
\makeatother

%set small captions without indentation,
%starting on second line
\setcapindent*{0em}
\addtokomafont{caption}{\small}
\begin{document}
\listoffigures
\chapter{blubb}
\blindtext[3]
\marginpar{this is text in the margin}\par
\begin{figure}
\margincap{A first long figure caption
in the left or right margin.}{\rule{3cm}{4cm}}
\end{figure}

\blindtext[2]
\marginpar{this is text in the margin}\par
\begin{figure}
\margincap[short caption]{A second long figure caption
in the leftor right margin.}{\rule{2cm}{1cm}}
\end{figure}

\blindtext[4]
\end{document}

First of all, thank you very much for the above solution!

Now the only thing that's a little bit annoying is that the captions for tables are vertically placed in the middle of the table rather than on top/bottom as with the figure captions. Any ideas?

Bild von Markus Kohm

Default vertical alignment of tabular environment center to the baseline. You may change this with the optional argument of the tabular environment to top or bottom alignment. See any LaTeX introduction about this.

I used your script and it works great, thank you!
Therefore there's one more thing I can't do: placing the captions in the margin, but aligned on the top of the figure/table line. Can you explain me how to move them, despite the default behaviour that wants them vertical aligned in the middle of the side?

now:
FFFF
FFFF
FFFF Caption
FFFF
FFFF

wanted:
FFFF Caption
FFFF
FFFF
FFFF
FFFF

Great thanks in advance,
Alberto

Bild von Markus Kohm

Have a look at mcaption package.

The mcaption package works very well, but what about the wrong references bug, as described in the manual? Is there a workaround to fix it?
Thank you.

Bild von Markus Kohm

Comments for "Figure/Table Captions in the Margin?" abonnieren