1

I need to move label text to the end of table caption, but there is newline at the end of text...

\documentclass[pdf, unicode, 12pt, a4paper, oneside, fleqn]{article}

\usepackage[utf8]{inputenc}
\usepackage[T2B]{fontenc}
\usepackage[english,russian]{babel}
\usepackage{caption}
\usepackage{longtable}


\DeclareCaptionFormat{reverse}{#3#2#1}
\DeclareCaptionLabelFormat{fullparens}{\bothIfFirst{#1}{ }#2}
\DeclareCaptionLabelSeparator{fill}{\hfill}
\captionsetup[longtable]{format=reverse,labelformat=fullparens,
              labelsep=fill}

\begin{document}

\begin{longtable}{|p{4.5cm}|p{11cm}|}
    \caption[Caption text]{Caption text} \label{table_1} \\
    \hline
    \endfirsthead
    \hline
    Title 1 & Title 2 \\
    \hline
    \endhead
    \hline
    \multicolumn{2}{c}{\textit{Продолжение на следующей странице}}
    \endfoot
    \hline
    \endlastfoot
    1 & 2 \\
\end{longtable}

\end{document}

And here is result: enter image description here Hot to remove new line? The result should be like this : "Text. Таблица 2".

3
  • Please extend your code snipped to complete small document, which we can copy and compile on our computers.
    – Zarko
    Commented May 15, 2017 at 1:34
  • Zarko, i extended my code.
    – toshunster
    Commented May 15, 2017 at 1:52
  • There are only two ways to put everything in one line: Put it all inside the \caption, or use \caption{} and put it all outside the caption. Commented May 15, 2017 at 3:03

1 Answer 1

2

try the following caption formatting:

\DeclareCaptionFormat{reverse}{#3#2#1}
\DeclareCaptionLabelFormat{fullparens}{(\bothIfFirst{#1}{ }#2)\hfill}
\DeclareCaptionLabelSeparator{fill}{\vspace{-\baselineskip}\hfil\qquad }
\captionsetup{format=reverse,
              labelformat=fullparens,
              labelsep=fill, labelfont=bf}

enter image description here

or

enter image description here

Complete MWE producing the second caption is:

\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%\usepackage[english,russian]{babel}
\usepackage{caption}
\usepackage{longtable}


\DeclareCaptionFormat{reverse}{#3#2#1}
\DeclareCaptionLabelFormat{fullparens}{(\bothIfFirst{#1}{ }#2)\hfill}
\DeclareCaptionLabelSeparator{fill}{\vspace{-\baselineskip}\hfil\qquad }
\captionsetup{format=reverse,
              labelformat=fullparens,
              labelsep=fill, labelfont=bf}

\begin{document}

\begin{longtable}{|p{4.5cm}|p{11cm}|}
    \caption[Caption text]{Very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, long caption text.} \label{table_1} \\
    \hline
    \endfirsthead
    \hline
    Title 1 & Title 2 \\
    \hline
    \endhead
    \hline
    \multicolumn{2}{c}{\textit{xxxxxxxxx xxxxxxxxxxxxx}}
    \endfoot
    \hline
    \endlastfoot
    1 & 2 \\
\end{longtable}
\end{document}

If you like to have table label aligned with right border of table, than change definition for label separator to

\DeclareCaptionLabelSeparator{fill}{\vspace{-\baselineskip}\hfill}

in you will obtain:

enter image description here

3
  • 1
    You can also use \captionsetup[longtable]... But I still see two lines. Commented May 15, 2017 at 2:59
  • 1
    @JohnKormylo, I believe that caption setup is independent from longtable. I suggest dirty hack, since I don't know, how to remove par which is somewhere hidden in caption definition on the end of caption main text.
    – Zarko
    Commented May 15, 2017 at 3:08
  • @Zarko - One can setup figure, table and any other declared \@captype to use different formats. Then again, you don't have to. Commented May 15, 2017 at 12:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .