[Tex/LaTex] Different caption alignment on different longtable pages

captionshorizontal alignmentlongtabletabu

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 
\endfirsthead


\caption[]{continued}\\
\endhead

\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}

Best Answer

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
        \endfirsthead

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

        \newpage
        \bottomrule

    \end{longtable}
\end{document}
Related Question