# Subfig caption doesn't start at start of line

I have a situation where the subfigure caption doesn't start at the start of the line. \captionsetup[table]{width=\textwidth} is added to try to have the caption take up the whole line rather than wrap at the boundaries of the table as recommended in Prevent wrapping of subtable captions in lyx.

%% LyX 1.6.7 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{caption}
\usepackage{subfig}
\captionsetup[table]{width=\textwidth}

\@ifundefined{showcaptionsetup}{}{%
\PassOptionsToPackage{caption=false}{subfig}}
\usepackage{subfig}
\makeatother

\usepackage{babel}

\begin{document}
%
\begin{table}
\caption{Valleys in promoters of genes correlated with overexpression by breast
cancer subtype}

\label{tab:vlyTallyUniqVlyMtchCntrlOvrExp}

\subfloat[Number of valleys in the promoter region marking overexpresses genes
in breast cancer by subtype]{\begin{raggedright}

\par\end{raggedright}

\begin{raggedright}
\label{tab:vlyTallyUniqCombinedVlyMtchCntrlOvrExp}
\par\end{raggedright}

\raggedright{}\begin{tabular}{|c|c|c|c|}
\cline{3-4}
\multicolumn{1}{c}{} &   & \multicolumn{2}{c|}{Over-expression}\tabularnewline
\cline{3-4}
\multicolumn{1}{c}{} &  & Basal & Luminal \tabularnewline
\hline
Marked & Basal  & 131  & 116\tabularnewline
\cline{2-4}
Cell line & Luminal  & 100  & 104\tabularnewline
\hline
\end{tabular}}

\subfloat[Directly overlapping valleys in promoters of genes correlated with
overexpression by breast cancer subtype]{\begin{raggedright}

\par\end{raggedright}

\begin{raggedright}
\label{tab:vlyTallyUniqOverlappingVlyMtchCntrlOvrExp}
\par\end{raggedright}

\raggedright{}\begin{tabular}{|c|c|c|c|}
\cline{3-4}
\multicolumn{1}{c}{} &   & \multicolumn{2}{c|}{Over-expression}\tabularnewline
\cline{3-4}
\multicolumn{1}{c}{} &  & Basal & Luminal \tabularnewline
\hline
Marked & Basal  & 26 & 18\tabularnewline
\cline{2-4}
Cell line & Luminal  & 20 & 10\tabularnewline
\hline
\end{tabular}}
\end{table}

\end{document}

-
Well, the reason that this happens was essentially described in my comment to the answer in that other post: you manually changed the \width which causes an overfull \hbox. It overflows symmetrically to the left and the the right, which is why when everything is centered it looks alright. But now that you have everything flush left, overflowing to the left and right symmetrically causes a problem. Suggestion: look at the other things you are allowed to set with \captionsetup. See if you can actually set the right margin to some negative value to compensate. – Willie Wong Jan 25 '11 at 19:56
interesting analysis @Willie Wong. It is mostly over my head right now and I cannot research more about the tex internals right now but this comment is helpful. When I get more time I will learn more. – denilw Jan 26 '11 at 23:33

write after your \begin{figure} a \centering or in LyX mark the contents of the float and choose centering
yes, that would also be ok, but it insert a \begin{center}...\end{center} environment. Better is a single command \centering. Don't know how it can be insert in LyX – Herbert Jan 26 '11 at 8:14
In my example, in Kile, adding \centering after \begin{table} doesn't do anything. What effect did it have for you? – denilw Jan 26 '11 at 17:35