5

How to make table caption left-aligned.

I tried \usepackage[singlelinecheck=off]{caption} but it did not work out. In other words it gives an error:

\DeclareFloatFont {tiny}{\tiny}% "scriptsize" is defined by floatrow, "t...

    \documentclass[a4paper]{article}
    \usepackage{graphicx}
    \usepackage[cmex10]{amsmath}
    \usepackage{mathtools}
    \usepackage[usenames]{color}
    \usepackage[table]{xcolor}
    \usepackage[left=2cm, right=2cm]{geometry}
    \usepackage{authblk}

    \usepackage{floatrow}
    \usepackage[labelsep=space]{caption}

    \DeclareFloatFont{tiny}{\tiny}
    \floatsetup[table]{font=footnotesize,capposition=top}

    \linespread{1.6}
    \renewenvironment{abstract}{%
    \noindent\bfseries\abstractname:\normalfont}{}

    \newcommand{\affilmark}[1]{\rlap{\textsuperscript{\itshape#1}}}

    \begin{document}

    \centerline{\LARGE Title}
    \vspace*{3ex}
    \begin{flushleft}\large
    A.B \affilmark{a},\quad
    A.D\affilmark{b}\\[2ex]
    \normalsize\itshape
    \textsuperscript{a}\,University of nowhere,\
    \upshape Corresponding author's email: \texttt{A.D@ieee.org}
    \end{flushleft}
    \date{}

    \begin{abstract}
    abstract goes here
    \end{abstract}


    \section{Introduction}
    some text goes here.

    \begin{figure}[!t]
    \includegraphics[width=0.4\textwidth, height=0.2\textwidth]
    \ffigbox[\FBwidth]
    \caption{Conventional  (a) ABCD. (b) EFGH.}
    \label{ABCDEFGH}
    \end{figure}

    \begin{table}[!t]

    \caption{performance of .}
    \label{tableII}
    \centering
    \definecolor{latexbl}{RGB}{28,220,240}
    \rowcolors{12}{black}{latexbl}

    \begin{tabular}  {|m{0.8cm}|m{0.6cm}|m{1.35cm}|m{1.1cm}|m{1.5cm}|m{1.1cm}|m{1.4cm}|m{0.7cm}|m{1.75cm}|m{1.2cm}|m{0.5cm}|}
    \hline
    \center Ref. & A &  B& C & D& E& F &G &H&I &J\\
    \hline
    \end{tabular}
    \begin{flushleft}
    some explanation
    \end{flushleft}
    \end{table}
    \end{document}

EDIT BY LOCKSTEP (moved from separate "answer"):

Here's a compilable example that doesn't show the problematic behaviour mentioned by you. Please use it as start-up aid to post a compilable example which does show the behaviour.

\documentclass{article}

\usepackage{floatrow}
\usepackage[singlelinecheck=off]{caption}

\begin{document}


\begin{table}
(Table content)
\caption{A table}
\end{table}

\end{document}
David Carlisle
  • 757,742
amir
  • 513
  • 5
    Please provide a complete minimal working example illustrating the problem. – Gonzalo Medina Sep 13 '11 at 21:00
  • @Gonzalo Medina: I edited my question. please read it again. – amir Sep 13 '11 at 22:45
  • 1
    It seems you are using code snippets from http://tex.stackexchange.com/questions/27097/changing-the-font-size-in-a-table. – lockstep Sep 13 '11 at 22:50
  • yes, that's right. – amir Sep 13 '11 at 22:50
  • You have to find out and show us the difference between my compilable example and the things you do (also as a compilable example). I only recognized the code snippet because it was part of another answer of mine. – lockstep Sep 13 '11 at 22:55
  • @lockstep : this is what I 'm using. please read my post again. – amir Sep 14 '11 at 00:01
  • 3
    If I take your new example and add singlelinecheck=off to the caption package options, the table caption is left-aligned. – lockstep Sep 14 '11 at 00:08
  • wow. but it gives me an error. I add \usepackage[singlelinecheck=off]{caption} it at the top of \DeclareFloatFont{tiny}{\tiny} \floatsetup[table]{font=footnotesize,capposition=top} and it gives the following error:l.13 \DeclareFloatFont {tiny}{\tiny} – amir Sep 14 '11 at 00:14
  • 2
    @amir: If you add \usepackage[singlelinecheck=off]{caption} to your preamble you'll try to load the caption package twice but with different options, and this does not work. So try doing what lockstep has suggested instead, which is adding singlelinecheck=off to the caption package options. –  Sep 14 '11 at 06:35

2 Answers2

10
\usepackage{caption}
\captionsetup{labelsep=space,justification=justified,singlelinecheck=off}

will do what you're asking. There's no error about "tiny".

egreg
  • 1,121,712
  • Thank you very much bro., egreg. It worked out but all figures and tables are at the center and all captions are left aligned according to text not to border of figures and tables. – amir Sep 14 '11 at 00:19
6

Seems like you want the captions to have the same width than the width of its figure/table. If this is the case, you can use the \ffigbox, and \ttabbox commands from the floatrow package. A little example:

\documentclass{article}
\usepackage{floatrow}
\usepackage[labelsep=space]{caption}

\DeclareFloatFont{tiny}{\tiny}
\floatsetup[table]{font=footnotesize,capposition=top}

\newcommand\Text{text text text text text text text}% just for the example

\begin{document}

\begin{figure}[!ht]
\ffigbox[\FBwidth]
{\caption{A figure with its caption having equal width to the figure width}\label{fig:test1}}
{\rule{4cm}{2cm}}
\end{figure}

\begin{table}[!ht]
\ttabbox[\FBwidth]
{\caption{A table with its caption having equal width to the table width}\label{fig:test1}}
{\begin{tabular}{p{3cm}p{3cm}}
\Text\Text & \Text\Text \\
\Text\Text & \Text\Text 
\end{tabular}
}
\end{table}

\end{document}

enter image description here

Moriambar
  • 11,466
Gonzalo Medina
  • 505,128
  • I edit my post (Figure is included). Caption is ok but Figure 1 is displayed below the caption. A line below the caption of figure. Sorry for bad english. caption of figure and then below the caption is Figure 1 C – amir Sep 14 '11 at 13:34
  • @amir: in the code you just posted there are some errors using the \ffigbox command. Your figure environment should be like this: \begin{figure}[!t] \ffigbox[\FBwidth]% {\caption{Conventional (a) ABCD. (b) EFGH.}\label{ABCDEFGH}} {\includegraphics[width=0.4\textwidth, height=0.2\textwidth]{<name>}} \end{figure} replacing <name> with the name of the file containing the image. Correct that part of your example code and report the outcome. – Gonzalo Medina Sep 14 '11 at 14:47