
배경색으로 표를 색칠하고, 배경색이 다른 캡션을 색칠하려고 합니다. 환경 을 사용해야 합니다 . , , , tabular
중 어느 것도 설정에 도움이 되지 않습니다. 다음 MWE를 살펴보십시오.tabulary
tablarx
tabu
tabular*
\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}
위의 코드는 다음 테이블을 생성합니다.
화살표로 표시된 간격이 캡션 배경색으로 덮일 수 있도록 캡션 배경을 확장하고 싶습니다. 다시 한번 말씀드리지만 환경을 이용해야 하며 tabular
테이블 너비는 전체 텍스트 너비를 덮어야 합니다. 현재 설정을 최소한으로 변경하는 데 도움을 주시면 감사하겠습니다.
답변1
태그를 달았으나 tcolorbox
사용하지 않고 있습니다!. 다음은 자신의 코드를 사용하는 버전입니다. 코드의 변경 사항에 대해 설명했습니다.
\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}