# Different caption alignment on different longtable pages

I'm using longtabu(longtable) for splitting a table on 2 and more pages, and i want to show different captions on pages.

This works fine, however i need the first caption to be aligned left, and the next captions aligned right.

I tried using \captionsetup from caption package, by putting it before \endfirsthead to set a different alignment for the first caption, but it changes alignments for all the pages. Any idea how i can achieve different alignments?

Minimal example

\documentclass[12pt,a4paper]{article}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{caption}

\captionsetup[table]{labelformat=simple,justification=raggedright,singlelinecheck=false}

\begin{document}

\begin{longtabu}{|X|}
\captionsetup{justification=raggedleft,singlelinecheck=false}
\caption{First caption\label{tab:cap1}}\\
\hline

\caption[]{continued}\\

\hline 1 \\
\hline 2 \\
\hline 3 \\
\hline 4 \\
\hline 5 \\
\hline 6 \\
\hline 7 \\
\hline 8 \\
\hline 9 \\
\hline 10 \\
\hline 11 \\
\hline 12 \\
\hline 13 \\
\hline 14 \\
\hline 15 \\
\hline 16 \\
\hline 1 \\
\hline 2 \\
\hline 3 \\
\hline 4 \\
\hline 5 \\
\hline 6 \\
\hline 7 \\
\hline 8 \\
\hline 9 \\
\hline 10 \\
\hline 11 \\
\hline 12 \\
\hline 13 \\
\hline 14 \\
\hline 15 \\
\hline 16 \\
\hline 1 \\
\hline 2 \\
\hline 3 \\
\hline 4 \\
\hline 5 \\
\hline 6 \\
\hline 7 \\
\hline 8 \\
\hline 9 \\
\hline 10 \\
\hline 11 \\
\hline 12 \\
\hline 13 \\
\hline 14 \\
\hline 15 \\
\hline 16 \\

\hline
\end{longtabu}
\end{document}
• Welcome to TeX.sx! Feel free to visit our TeX.SX starter guide to get the most out our site. – Peter Jansson May 28 '13 at 13:32
• I would recommend staying away from the tabu package. The author has stated he is implementing a new version that is not going to be backwards compatible and most likely will have issues with other packages. You may want to use the longtable package instead. I'll write a possible answer – Mario S. E. May 28 '13 at 13:36
• I've used longtabu for variable width columns(which longtable seems to lack) and longtable page breaking, which seemed the best of both worlds. – Placinta May 28 '13 at 17:10

You could define a couple of new commands that change the captionsetup and then pass arguments to caption. It is then possible to set a document-wide parameter, such as labelfont=bf that affects both captions.

\documentclass[12pt,a4paper]{article}

\usepackage{longtable}
\usepackage{caption}
\usepackage{booktabs}

\captionsetup[table]{singlelinecheck=false,labelfont=bf}
\newcommand\firstcaption[1]{\captionsetup{justification=raggedright}\caption{#1}}
\newcommand\followingcaption[1]{\captionsetup{justification=raggedleft,labelsep=space}\caption[]{#1}}

\begin{document}
\listoftables%
\clearpage%
\renewcommand*{\arraystretch}{1}
\begin{longtable}[t]{l}
\firstcaption{Summary of qualitative risk factors\label{tab:label1}}\\
\toprule
\textbf{First Column} \\
\midrule

\followingcaption{(Continue): Summary of proven determinants for falling}\\
\toprule
\textbf{Author} \\
\midrule

\newpage
\bottomrule

\end{longtable}
\end{document}
• So my mistake was that i should have globally set the captionsetup twice, once to display captions in what style, and afterwards to reset it. And the newcommand approach seems slick, thanks. – Placinta May 28 '13 at 17:12

As mentioned in my comments, I would really suggest to avoid the tabu package.

Here is a sample solution with longtable and booktabs:

\documentclass[12pt,a4paper]{article}
\usepackage{longtable}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{hyperref}

\captionsetup[table]{labelformat=simple,justification=raggedright,singlelinecheck=false}

\begin{document}

\renewcommand*{\arraystretch}{1}
\begin{longtable}[t]{l}
\caption{Summary of qualitative risk factors}\label{tab:label1}\\
\toprule
\textbf{First Column} \\
\midrule
\caption*{\raggedleft Table \ref{tab:label1} (Continue): Summary of proven determinants for falling  }\\
\toprule
\textbf{Author} \\
\midrule

\midrule 1 \\
\midrule 2 \\
\midrule 3 \\
\midrule 4 \\
\midrule 5 \\
\midrule 6 \\
\midrule 7 \\
\midrule 8 \\
\midrule 9 \\
\midrule 10 \\
\midrule 11 \\
\midrule 12 \\
\midrule 13 \\
\midrule 14 \\
\midrule 15 \\
\midrule 16 \\
\midrule 1 \\
\midrule 2 \\
\midrule 3 \\
\midrule 4 \\
\midrule 5 \\
\midrule 6 \\
\midrule 7 \\
\midrule 8 \\
\midrule 9 \\
\midrule 10 \\
\midrule 11 \\
\midrule 12 \\
\midrule 13 \\
\midrule 14 \\
\midrule 15 \\
\midrule 16 \\
\midrule 1 \\
\midrule 2 \\
\midrule 3 \\
\midrule 4 \\
\midrule 5 \\
\midrule 6 \\
\midrule 7 \\
\midrule 8 \\
\midrule 9 \\
\midrule 10 \\
\midrule 11 \\
\midrule 12 \\
\midrule 13 \\
\midrule 14 \\
\midrule 15 \\
\midrule 16 \\

\bottomrule

\end{longtable}

\end{document}

As you can see, I added a couple of features I thought you might like:

1. I don't use the tabu package (see why here).

2. I'm using the booktabs package to improve the horizontal lines

3. I'm not defining new commands (you could also see this as a weakness).

4. I'm using hyperref to be able to "jump back" to the beginning of the table

• Essentially inserting \raggedleft into the caption solves the problem. – Placinta May 28 '13 at 17:14
• @Placinta Please see my edited answer :) – Mario S. E. May 28 '13 at 21:31