3

alt text

Could someone provide me with an elegant solution to prevent wrapping of a table caption in lyx? It must wrap at the end of the line, not at the end of the table.

%% 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}{\\}

\makeatother

\usepackage{babel}

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


\label{tab:vlyTallyUniqVlyMtchCntrlOvrExp}

\subtable[Number of valleys in the promoter region marking overexpresses
genes in breast cancer by subtype]{

\label{tab:vlyTallyUniqCombinedVlyMtchCntrlOvrExp}

\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}

}
\end{table}


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

\label{tab:vlyTallyUniqOverlappingVlyMtchCntrlOvrExp}

\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}
4
  • Huh, your example does not compile for me, it complains about the \subtable command. Commented Jan 19, 2011 at 19:23
  • Ah... your included file is a bit odd. It probably should \usepackage{subfigure}, and I am not quite sure why lyx decided that your two subtables ought to belong to two separate table environments. Commented Jan 19, 2011 at 19:30
  • I don't think either subfigure or subfig will do what you want. After all, one of the goals of those packages allow the subfloats to fit on the same line (horizontally) whenever possible. So it doesn't make much sense to have an option to force the caption to be at full width. Commented Jan 19, 2011 at 19:36
  • Hi @Willie Wong. Thanks, for the comments. I am also not sure why lyx decided that your two subtables ought to belong to two separate table environments, I didn't create them that way before the export to LaTeX. I believe you are right when you say my example should use \usepackage{subfigure}.
    – denilw
    Commented Jan 19, 2011 at 21:28

2 Answers 2

2

Use the packages subfig and caption

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage{subfig}
\usepackage{caption}
\captionsetup[table]{position=top,width=\textwidth}

\begin{document}
%
\begin{table}
\caption{Valleys in promoters of genes correlated with overexpression by breast
cancer subtype}\label{tab:vlyTallyUniqVlyMtchCntrlOvrExp}
\centering
\subfloat[Number of valleys in the promoter region marking overexpresses
genes in breast cancer by subtype]{\label{tab:vlyTallyUniqCombinedVlyMtchCntrlOvrExp}
\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]{\label{tab:vlyTallyUniqOverlappingVlyMtchCntrlOvrExp}
\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}

alt text

6
  • Nice idea, did not thought about that. The only caveat I see is that this solution produces overfull hboxes.
    – user2574
    Commented Jan 19, 2011 at 19:57
  • Ah, good idea there. But like Axel said, setting \width violates the margins. Not only does it produce hbox errors, if you started with two tables that could be placed side-by-side on one row, this will break subfloat. (Try removing the first column from one of the tables. The output will be clobbered.) Commented Jan 19, 2011 at 20:13
  • @Axel: true, but you already know, that not every overfull hbox will be seen in the output ... ;-)
    – user2478
    Commented Jan 19, 2011 at 20:36
  • This works in Lyx with slight modifications.
    – denilw
    Commented Jan 19, 2011 at 21:33
  • The essence of this solution as far as I can tell is to add the line \captionsetup[table]{position=top,width=\textwidth} before your table float. Simple and effective.
    – denilw
    Commented Jan 19, 2011 at 21:45
3

Using the/my subcaption package instead of subfig one can use the optional parameter of \subcaptionbox to enlarge the width of the sub-figure so the whole page width will be used. Example code:

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}

\usepackage{caption,subcaption}

\makeatletter

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

\makeatother

\usepackage{babel}

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

\label{tab:vlyTallyUniqVlyMtchCntrlOvrExp}

\subcaptionbox{%
Number of valleys in the promoter region marking overexpresses genes in breast cancer by subtype
\label{tab:vlyTallyUniqCombinedVlyMtchCntrlOvrExp}}
[\linewidth]
{%
\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}

}
\end{table}


%
\begin{table}
\subcaptionbox{%
Directly overlapping valleys in promoters of genes correlated
with overexpression by breast cancer subtype
\label{tab:vlyTallyUniqOverlappingVlyMtchCntrlOvrExp}}
[\linewidth]
{%
\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}

(Unfortunately I have no clue about Lyx, so I don't know how to port this into Lyx.)

For even more fancy stuff with subfigures take a look at the floatrow package.

1
  • This did not work for me in Lyx or Kile. In Kile the most notable problem was that the subfigure lettering was not correct. I'm not sure if this could be easily fixed but the other solution works for me.
    – denilw
    Commented Jan 19, 2011 at 21:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .