9

How I can align caption for table like this?

enter image description here

Current code:

\begin{table}[h]
  \caption{}
  \centering
    \begin{tabular}{|l|r|r|l|}
        \hline
        № & X     & Y     & Время выполнения м:сс \\ \hline
        1 & 15000 & 16000 & 0:57                  \\ \hline
        2 & 16000 & 17000 & 0:19                  \\ \hline
        3 & 17000 & 18000 & 0:10                  \\ \hline
        4 & 18000 & 19000 & 0:03                  \\ \hline
        5 & 19000 & 20000 & 0:02                  \\ \hline
        6 & 20000 & 21000 & 0:01                  \\ \hline
        7 & 60000 & 61000 & 0:01                  \\ \hline
    \end{tabular}
\end{table}
5

The requirement for traditional \caption right/left justification implies that the table be boxed. You can do this with ctable and caption:

enter image description here

\documentclass{article}
\usepackage{ctable}% http://ctan.org/pkg/ctable
\usepackage{caption}% http://ctan.org/pkg/caption
\captionsetup[table]{justification=raggedleft,singlelinecheck=off}
\begin{document}
\ctable
  [caption={Some caption}]% <options>
  {|l|r|r|l|}% <column spec>
  {}% <footnotes>
  {% <table>
    \hline
    No & X     & Y     & Hours:Minutes \\ \hline
    1 & 15000 & 16000 & 0:57                  \\ \hline
    2 & 16000 & 17000 & 0:19                  \\ \hline
    3 & 17000 & 18000 & 0:10                  \\ \hline
    4 & 18000 & 19000 & 0:03                  \\ \hline
    5 & 19000 & 20000 & 0:02                  \\ \hline
    6 & 20000 & 21000 & 0:01                  \\ \hline
    7 & 60000 & 61000 & 0:01                  \\ \hline
  }
\end{document}
9

You can use the \ttabbox and \FBwidth commands from the floatrow package to get a caption with a width equal to the table width, and then perform an adjustment to the caption justification with the help of the caption package:

\documentclass{article}
\usepackage[russian]{babel}
\usepackage{floatrow,caption}

\begin{document}

\ttabbox[\FBwidth]{}{%
  \captionsetup{justification=raggedleft,singlelinecheck=off}
  \caption{}
    \begin{tabular}{|l|r|r|l|}
        \hline
        № & X     & Y     & text \\ \hline
        1 & 15000 & 16000 & 0:57                  \\ \hline
        2 & 16000 & 17000 & 0:19                  \\ \hline
        3 & 17000 & 18000 & 0:10                  \\ \hline
        4 & 18000 & 19000 & 0:03                  \\ \hline
        5 & 19000 & 20000 & 0:02                  \\ \hline
        6 & 20000 & 21000 & 0:01                  \\ \hline
        7 & 60000 & 61000 & 0:01                  \\ \hline
    \end{tabular}%
}

\end{document}

enter image description here

4

Alternatively, you can use caption in combination with the threeparttable package. While threeparttable's main function is to allow for table notes, it also restricts the caption width so that it can properly be aligned.

 

\documentclass{article}
\usepackage{caption}
\usepackage{threeparttable}

\begin{document}
\begin{table}[h]
    \centering
    \begin{threeparttable}
        \captionsetup{justification=raggedleft,singlelinecheck=false}
        \caption{}      
        \begin{tabular}{|l|r|r|l|}
            \hline
            № & X     & Y     & Время выполнения м:сс \\ \hline
            1 & 15000 & 16000 & 0:57                  \\ \hline
            2 & 16000 & 17000 & 0:19                  \\ \hline
            3 & 17000 & 18000 & 0:10                  \\ \hline
            4 & 18000 & 19000 & 0:03                  \\ \hline
            5 & 19000 & 20000 & 0:02                  \\ \hline
            6 & 20000 & 21000 & 0:01                  \\ \hline
            7 & 60000 & 61000 & 0:01                  \\ \hline
        \end{tabular}
    \end{threeparttable}    
\end{table} 
\end{document}
4

One could use \captionbox offered by the caption package (since version 3.2):

\documentclass{article}
\usepackage{caption}

\captionsetup[table]{position=t,justification=raggedleft,slc=off}

\begin{document}
\begin{table}
    \centering
    \captionbox{\label{table1}}{%
        \begin{tabular}{|l|r|r|l|}
            \hline
            No & X     & Y     & Test \\ \hline
            1 & 15000 & 16000 & 0:57                  \\ \hline
            2 & 16000 & 17000 & 0:19                  \\ \hline
            3 & 17000 & 18000 & 0:10                  \\ \hline
            4 & 18000 & 19000 & 0:03                  \\ \hline
            5 & 19000 & 20000 & 0:02                  \\ \hline
            6 & 20000 & 21000 & 0:01                  \\ \hline
            7 & 60000 & 61000 & 0:01                  \\ \hline
        \end{tabular}}
\end{table} 
\end{document}

Unfortunately I did not found the time to document \captionbox yet, but its syntax is identical to \subcaptionbox which is documented in the subcaption package documentation.

0

Instead of using captionbox, threeparttable, etc., simply include singlelinecheck=false with justification=RaggedLeft or justification=raggedleft and choose any of plain/hang for format if not stisfied yet. More probably, format=plain is proper for publications standards in Russia.

\usepackage{caption}
\captionsetup[table]{singlelinecheck=false, justification=RaggedLeft}

Take into account, caption may be placed up to end of right border and turn out of table, when narrow table is centered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.