Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Captions of wide longtables are indented

687 views
Skip to first unread message

Oleg Paraschenko

unread,
Oct 7, 2005, 8:27:52 AM10/7/05
to
Hello,

some of my longtables are wider than \hsize (=\columnwidth). It's ok.
The problem is the left-aligned captions of such tables. If a table is
X too wide, then the caption is indented by X.

Any suggestions how to avoid indenting? Or, at least, any ideas why it
happens?

An example to reproduce the problem:

\documentclass{article}
\usepackage{longtable}
\usepackage[nooneline,justification=raggedright]{caption}
\begin{document}
\begin{longtable}[l]{|p{\hsize}|p{50pt}|}
row1col1&row1col2\\
row2col1&row2col2\\
\caption{my table}
\end{longtable}
\end{document}

In this example, the caption is indented by 50pt. I use:

longtable 2004/02/01 v4.11 Multi-page Table package (DPC)
caption 2004/01/23 v3.0a Customising captions (AS)

Thank you in advance,

--
Oleg Paraschenko olpa@ http://uucode.com/
http://uucode.com/blog/ Generative Programming, XML, TeX, Scheme

Axel Sommerfeldt

unread,
Oct 7, 2005, 11:48:40 AM10/7/05
to
Hi Oleg,

"Oleg Paraschenko" <ole...@gmail.com> wrote:

> Any suggestions how to avoid indenting? Or, at least, any ideas why it
> happens?

Have you tried

\begin{longtable}[l]{|p{50pt}|p{50pt}|}

instead of

\begin{longtable}[l]{|p{\hsize}|p{50pt}|}

? This gives a wired result, too, and by this example maybe you could
imagine what is going on here:

The caption in a longtable is typeset as centered multicolumn -- this
means the caption is centered inside the longtable. Therefore you run
into problems when using a caption with a left-justified (or right-
justified) caption, for example if the caption has a greater width than
the longtable it will go into the margin. Try this:

\documentclass{article}
\usepackage{longtable}
\begin{document}
\noindent Ordinary text\ldots
\begin{longtable}[l]{cc}
A & B \\
\caption{A longtable with a caption}
\end{longtable}
\noindent Ordinary text\ldots
\end{document}

What can you do about this?

1. Try to find a appropriate value of \LTcapwidth. A longtable caption
will (nearly) always be typeset using this width.

2. Take a look at the floatrow package. As far as I know it has an option
to typeset the caption exactly as wide as the longtable.

3. Try to patch \LT@makecaption from the longtable (or caption) package.
In this macro the multicolumn will be typeset and you can try to adjust
some things here. The upcoming caption package v3.1 will offer an user
interface for such longtable caption justifications, but I'm sorry, I
will not release such a (alpha/beta) version within the next weeks.

> An example to reproduce the problem:

> [...]


> \begin{longtable}[l]{|p{\hsize}|p{50pt}|}

> [...]


> In this example, the caption is indented by 50pt.

Yes, of course. (But the indention is half the more-than-hsize width, not
50pt.) When using the caption package (without adjusting \LTcapwidth or
\captionsetup{width=...}) the caption width will be \hsize and will be
centered to the longtable -- therefore you get this result.

Using

\setlength\LTcapwidth{\hsize}
\advance\LTcapwidth by 50pt

before \begin{longtable}... will result in a better match, but not
perfect because the width of the longtable is more than \hsize+50pt.

HTH,
Axel

Oleg Paraschenko

unread,
Oct 12, 2005, 8:17:25 AM10/12/05
to
Hi Axel,

thank you for reply. Your explanation and the source code of
\LT@makecaption revealed me the reason of the problem.

Among of the suggestions, I've choosen patching the definition of
\LT@makecaption. It combines code from the longtable and caption2
packages, and uses the fact that my captions are always of \hsize.

\def\LT@makecaption#1#2#3{%
\LT@mcol\LT@cols l{\hskip-\tabcolsep\hbox to\z@{\parbox[t]\hsize{%
\captionfont\selectfont {#2: }#3%
\endgraf\vskip\baselineskip}%
\hss}}}

Axel Sommerfeldt

unread,
Oct 12, 2005, 10:38:59 AM10/12/05
to
Hi Oleg,

> thank you for reply. Your explanation and the source code of
> \LT@makecaption revealed me the reason of the problem.

That's fine.

> Among of the suggestions, I've choosen patching the definition of
> \LT@makecaption. It combines code from the longtable and caption2
> packages, and uses the fact that my captions are always of \hsize.

BTW: Your code should also work together with the actual version of the
caption package 3.0, so I suggest migrating from caption2 to caption 3.0.

> \captionfont\selectfont {#2: }#3%

If you want to make \caption* working, you need to use #1, too:

\captionfont\selectfont #1{#2: }#3%

HTH,
Axel

0 new messages