Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
add comment

4 Answers 4

up vote 4 down vote accepted

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}
share|improve this answer
add comment

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

share|improve this answer
add comment

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}
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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