Quantcast
Channel: Matching width of Caption background with Table width - TeX - LaTeX Stack Exchange
Viewing all articles
Browse latest Browse all 2

Matching width of Caption background with Table width

$
0
0

I am trying to color a table with a background color and the caption with a different background color. I must use the tabular environment, none of the tabulary, tablarx, tabu, tabular* will be helpful for my setup. Please have look at the following MWE:

\documentclass{article}\usepackage[usenames,svgnames,dvipsnames]{xcolor}\usepackage{booktabs}\usepackage{array}\usepackage[font={bf}]{caption}\captionsetup[table]{box=colorbox,boxcolor=orange!20}\begin{document}%===========================================\section{ Gender Distribution}%===========================================\begin{center}\fcolorbox{yellow!20}{yellow!20}{%\parbox{\textwidth}{%\centering\setlength{\abovecaptionskip}{10pt}\setlength{\belowcaptionskip}{-3pt}\captionof{table}{Duration of Use and Gender Distribution}\begin{tabular}{>{\hspace{1pc}}c>{\hspace{1pc}}c>{\hspace{1pc}}c>   {\hspace{1pc}}c<{\hspace{1pc}}}\toprule& Female & Male & All \\ \midrule1 year- 2 years & 2 (50) & 2 (13.3) & 4 \\ 2 years - 3 years & 0 (0) & 4 (26.7) & 4 \\ 3 years +& 1 (25) & 3 (20) & 4 \\ 6 months- 1 year & 1 (25) & 3 (20) & 4 \\ Less than 6 months & 0 (0) & 3 (20) & 3 \\ \midruleTotal & 4 & 15 & 19 \\ \bottomrule\footnotesize{Source:Airtel Survey}\end{tabular}}}\end{center}\end{document}

Above code produces following table:

enter image description here

I would like to extend the caption background so that the spaced denoted by arrow could be covered by the caption background color. Again, please note that I have to use the tabular environment and the table width should cover the full text width. I would greatly appreciate any help with minimum changes in the current setup.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>