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.

I have a table whose table number should be right-aligned and its caption should be center-aligned on the next line like this:

                          Table 1
           Caption
---------------------------------
|    |       |        |         |
---------------------------------

I found the caption package which is a powerful tool for changing caption styles, but it doesn't allow to solve my problem.

share|improve this question

migrated from stackoverflow.com Oct 23 '12 at 11:46

This question came from our site for professional and enthusiast programmers.

1 Answer 1

With the caption package, you may declare a new format that will add \hfill at the very start of the caption (hereby making its first line raggedright).

(In the following example, I also use the floatrow package to center the tabular material and to allow switching the caption's position from below to above.)

\documentclass{article}

\usepackage{caption}
\DeclareCaptionFormat{hfillstart}{\hfill#1#2#3\par}
\captionsetup[table]{format=hfillstart,labelsep=newline,justification=centering}

\usepackage{floatrow}
\floatsetup[table]{capposition=top}

\newcommand{\sometext}{Lorem ipsum dolor sit amet, consectetuer
    adipiscing elit. Ut purus elit, vestibulum ut, placerat ac,
    adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu
    libero, nonummy eget, consectetuer id, vulputate a, magna.}

\begin{document}

This is normal text. \sometext

\begin{table}
(Tabular material)
\caption{This is a table caption. \sometext}
\end{table}

\end{document}

enter image description here

share|improve this answer
    
I believe that loading floatrow just to avoid \centering is exaggerated. :) –  egreg Oct 23 '12 at 12:10
    
@egreg It also allows to switch the caption's position. ;-) –  lockstep Oct 23 '12 at 12:12
    
@lockstep many thanks! it works like a charm! :) –  martemiev Oct 23 '12 at 13:55
    
@martemiev You're welcome -- and don't forget to accept my answer. ;-) –  lockstep Oct 23 '12 at 13:57

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.