[comp.text.tex] Help needed to center a multi-line tabel caption

xuzhiqin@aludra.usc.edu (Xuzhi Qin) (03/12/91)

Hi,
	Could somebody out there help me to solve the following problem ?

	I often have long table captions which make the captions multi-line.
As I understand, LaTeX can only center the first line in a caption not the
rest line of it. How can I make it all centered? Is there any way to break
a line manually, as in \author environment using \\?

Example:

LaTeX ---> Table 1. This is a very long table caption. LaTeX only center the
         first line of it. 

I want --> 	   Table 1. This is a very long table caption.
	 It can be broken manually. All lines are centered as \maketitle.

Thanks in advance.

Xuzhi Qin
(pronouncing like Shuchi Ching)

ogawa@orion.arc.nasa.gov (Arthur Ogawa) (03/12/91)

In article <15704@chaph.usc.edu> xuzhiqin@aludra.usc.edu (Xuzhi Qin) writes:
|	I often have long table captions which make the captions multi-line.
|As I understand, LaTeX can only center the first line in a caption not the
|rest line of it. How can I make it all centered? Is there any way to break
|a line manually, as in \author environment using \\?

Examine the following LaTeX job:

\documentstyle{book}
% Now that we have read in book.sty, rewrite one of its definitions.
% Figure and table captions will be centered, instead of justified.
\makeatletter
\long\def\@makecaption#1#2{%
 \vskip 10pt 
 \setbox\@tempboxa\hbox{#1: #2}%
 \ifdim \wd\@tempboxa >\hsize
  \begin{center}%
  #1: #2%
  \end{center}%
  \else \hbox to\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
 }%
\makeatother

% Here is a document instance. Note the use of the \caption command:
% The material to appear in the list of tables appears within brackets [];
% The text of the formatted caption appears within braces {}.
% Note that the \\ must not be sent to the lot! (There's more than one way  
% to approach this problem.)
\begin{document}
\begin{table}[h]
Content of table Content of table Content of table Content of table Content of
table Content of table 
\caption[This is a very long table caption.]{%
 This is a very long table caption.\\LaTeX only centers the first line of it.
 This is a very long table caption.\\LaTeX only centers the first line of it.\\
 This is a very long table caption. LaTeX only centers the first line of it.
 }%
\end{table}
\end{document}

The individual lines of the caption will appear centered on the text
width.  If you want the figure and table caption formatting to be
different from each other, see my earlier post to Bruggink's query (or
email me).
Arthur Ogawa        Internet: ogawa@orion.arc.nasa.gov  Ph: 1/415/691-1126
TeX consultant      AppleLink: ogawa                    FAX:1/415/962-1969