7

Possible Duplicate:
How to reduce space between image and its caption?

I am working on one example in which i need to draw one table and its caption. How can i control the space between Title, Table and caption. I want to minimize the spacing.

 \usepackage{transparent}
 \usepackage{lmodern}
  \usepackage[T1]{fontenc}
  \usepackage{hyphenat}
 \usepackage{xstring}
 \usepackage{forloop}
 \usepackage{collcell}
 \usepackage{longtable}
 \usepackage{makecell}
 \usepackage{varwidth}
 \usepackage{fancyhdr}
 \usepackage{array,multirow,colortbl}
 \usepackage{caption}
 \usepackage{subfig}
 \usepackage[table]{xcolor}
 \pagestyle{fancy}
  \fancyhf{} % sets both header and footer to nothing
 \renewcommand{\headrulewidth}{0pt} 
 \fancyfoot{}
 \begin{document}

 \arrayrulecolor{white}


  \definecolor{maincol}{rgb}{.118, .565, 1.00}   
 \definecolor{textcol}{rgb}{.118, .565, 1.00}  
 \newcolumntype{P}[1]{>{\collectcell\AddBreakableChars}p{#1}<{\endcollectcell}}


 \captionsetup[table]{aboveskip=0pt} 
 \captionsetup[table]{belowskip=10pt} 
 \textcolor{textcol}{\textbf{ XYZ }}   
  \scriptsize  

 \arrayrulecolor{white} 
 \begin{longtable}{|M{1.4cm}|M{1.4cm}|M{1cm}|M{3.7cm}|M{1.8cm}|M{1.4cm}|} 
 \rowcolor{maincol} \textbf{ \textcolor{white}{A}} &\textbf{      \textcolor{white}{B}} &\textbf{ \textcolor{white}{C}} &\textbf{ \textcolor{white}{D}} &\textbf{ \textcolor{white}{E}}  &\textbf{    \textcolor{white}{F} }\\ 
 \hline 
 \rowcolor{rowcol} 
  AA 
   &  AA&  A&  DDD  & [1, 2]  &  TTT \\ 
    \hline 
    \rowcolor{rowcol} 
    & & & & Total  & TTT \\ 
    \end{longtable} 
    \scriptsize  
     \textit{This is Caption} 
    \end{document}
manish
  • 9,111

2 Answers2

11

For your purpose you can set skip=0pt using the caption-package.

As was asked by the OP:

How can i control the font size of caption?

font={<font options>}

The available optiones are: scriptsize, footnotesize, small, normalsize, large and Large. Simply add this to your captionsetup.

For other options regarding the captions, you should check out the documentation.

Here an example.

\documentclass{article}

\usepackage{caption}
\captionsetup{skip=0pt}

\begin{document}

\begin{table}
\centering
\begin{tabular}{llr}
\hline
\multicolumn{2}{c}{Item}             \\
\cline{1-2}
Animal    & Description & Price (\$) \\
\hline
Gnat      & per gram    & 13.65      \\
          & each        & 0.01       \\
Gnu       & stuffed     & 92.50      \\
Emu       & stuffed     & 33.33      \\
Armadillo & frozen      & 8.99       \\
\hline
\end{tabular}
\caption{The classic}
\end{table}

\end{document}

Result

iamge

David Carlisle
  • 757,742
rtzll
  • 5,531
3

Thank you for giving your entire document ;-). However, for tables the best practice is to put the captions above the table. In your case putting skip=0pt and putting the caption above the longtable :

 \documentclass{article}
 \usepackage{transparent}
 \usepackage{lmodern}
  \usepackage[T1]{fontenc}
  \usepackage{hyphenat}
 \usepackage{xstring}
 \usepackage{forloop}
 \usepackage{collcell}
 \usepackage{longtable}
 \usepackage{makecell}
 \usepackage{varwidth}
 \usepackage{fancyhdr}
 \usepackage{array,multirow,colortbl}
 \usepackage{caption}
 \usepackage{subfig}
 \usepackage[table]{xcolor}
 \pagestyle{fancy}
  \fancyhf{} % sets both header and footer to nothing
 \renewcommand{\headrulewidth}{0pt} 
 \fancyfoot{}
% \begin{document}

 \arrayrulecolor{white}

  \definecolor{rowcol}{rgb}{.118, .565, 1.00}
  \definecolor{maincol}{rgb}{.118, .565, 1.00}   
 \definecolor{textcol}{rgb}{.118, .565, 1.00}  
 \newcolumntype{P}[1]{>{\collectcell\AddBreakableChars}p{#1}<{\endcollectcell}}
 \newcolumntype{M}[1]{>{\centering\arraybackslash}p{#1}}
 \begin{document}
 \captionsetup[table]{skip=0pt}        %% here
% \captionsetup[table]{belowskip=10pt} 
 \textcolor{textcol}{\textbf{ XYZ }}   
  \scriptsize  
 \arrayrulecolor{white} 
 \begin{longtable}{|M{1.4cm}|M{1.4cm}|M{1cm}|M{3.7cm}|M{1.8cm}|M{1.4cm}|} 
 \caption{this is caption}\\\hline                                       %% caption here
 \rowcolor{maincol} \textbf{ \textcolor{white}{A}} &\textbf{\textcolor{white}{B}} &\textbf{ \textcolor{white}{C}} &\textbf{ \textcolor{white}{D}} &\textbf{ \textcolor{white}{E}}  &\textbf{    \textcolor{white}{F} }\\ 
 \hline 
 \rowcolor{rowcol} 
  AA  &  AA&  A&  DDD  & [1, 2]  &  TTT \\ 
    \hline 
    \rowcolor{rowcol} 
    & & & & Total  & TTT \\ 
    \end{longtable} 
    \scriptsize  
    \end{document}

enter image description here

Please note that caption of tables and figures is inserted through a syntax:

\caption[short caption]{long caption}

where short caption is used for running content like headers and list of tables and long caption is what is seen above the table. Also, in long table, the width of the caption is fixed at 4in by default. You may change the width by putting a suitable value in

\setlength{\LTcapwidth}{5in}

in your preamble if you have a broader caption.

  • How can i move XYZ bit down? – manish Jan 16 '13 at 09:07
  • @user15662: Already skip=0pt. That means the intermediate space is only the baselineskip. If you want to reduce that also (which I think a bad idea), use something like \textcolor{textcol}{\textbf{ XYZ }} \vspace{-.5\baselineskip} –  Jan 16 '13 at 09:21