
Estou tentando colorir uma tabela com uma cor de fundo e a legenda com uma cor de fundo diferente. Devo usar o tabular
ambiente, nenhum dos tabulary
, tablarx
, tabu
, tabular*
será útil para minha configuração. Por favor, dê uma olhada no seguinte 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 \\
\midrule
1 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 \\
\midrule
Total & 4 & 15 & 19 \\
\bottomrule
\footnotesize{Source:Airtel Survey}\end{tabular}
}
}
\end{center}
\end{document}
O código acima produz a seguinte tabela:
Gostaria de estender o fundo da legenda para que o espaçamento indicado pela seta pudesse ser coberto pela cor de fundo da legenda. Novamente, observe que preciso usar o tabular
ambiente e a largura da tabela deve cobrir toda a largura do texto. Eu apreciaria muito qualquer ajuda com alterações mínimas na configuração atual.
Responder1
Você marcou tcolorbox
, mas não está usando! Aqui está uma versão usando seu próprio código. Comentei as alterações feitas no código.
\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}
\fboxsep0pt %% <<<--- add this.
\fcolorbox{yellow!20}{yellow!20}{%
\parbox{\textwidth}{%
\fboxsep5pt% %%<<--- add this here for making caption's height large
\centering
%\setlength{\abovecaptionskip}{10pt}
%\setlength{\belowcaptionskip}{-3pt} %% <<<--- this messes up
\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 \\
\midrule
1 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 \\
\midrule
Total & 4 & 15 & 19 \\
\bottomrule
\footnotesize{Source:Airtel Survey}\end{tabular}
}% %<<<<--- % needed here
% <<<--- don't leave blank line here for better
}
\end{center}
\end{document}