[Tex/LaTex] Different caption styles for figures and for tables

captionshorizontal alignment

I need to have different caption format for figures and for tables. Captions for figures have to be centered and captions for tables – left aligned. How to define this?

Best Answer

Use the caption package and its justification=raggedright option. If desired, add singlelinecheck=false to make sure that single-line captions are also typeset raggedright.

\documentclass{article}

% Optional: float content (apart from caption) centered
\makeatletter
\g@addto@macro\@floatboxreset\centering
\makeatother

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

\begin{document}

\begin{figure}
\rule{1cm}{1cm}
\caption{A figure}
\end{figure}

\begin{table}
(Tabular material)
\caption{A table}
\end{table}

\end{document}