3

I am trying to make the tcolorbox to fit its content, a table, and not to span to textwidth . I've look through a lot of questions (1,2,3,4) but nothing seem to work, i tried tabularx too.

Unless I manually adjust the text width but then the footnotes also disappears. I believe its something very simple but I can't see where is my mistake.

table without extra space inside tcolorbox

\PassOptionsToPackage{usenames,dvipsnames,svgnames,table,cmyk,x11names}{xcolor}
\documentclass[openany]{memoir}
\usepackage[most]{tcolorbox}
\usepackage{array,booktabs}
\usepackage{tabularx}
\usepackage{footnote}
\usepackage{varwidth}


\tcbset{tab2/.style={
        enhanced,fonttitle=\bfseries,fontupper=\normalsize\sffamily,colback=yellow!10!white,colframe=red!50!black,colbacktitle=Salmon!40!white,coltitle=black,center title}
}

\begin{document}
    
    \rowcolors{2}{MistyRose1}{MistyRose1!30!white}

%\begin{threeparttable}
\begin{tcolorbox}[tab2, hbox, % text width=0.5\textwidth, 
    tabulars={lc}
    ,center,center title,title=Tabela Nutricional Semanal,boxrule=0.75pt,]
    %\begin{varwidth}{\textwidth}
    %\begin{tabularx}{lX}
    
    {\textbf{Alimento}} & {\textbf{Quantidade (g)}} 
    %& \multirow{2}{=}{\textbf{Recomendado pela (g)}} 
    \\  %\hline
    Carne & 200\\ % & 392 \\
    Gorduras & 170\\ % & 270 \\
    Queijo Quark & 100 \\ %& ND\\
    Pão & 2'450   \\
    Açúcar\footnote{This is the footnote} & 80  \\
    Geleia & 100  \\
    Cereais & 150  \\
    Farinha & 125  \\
    Substituto de café & 63  \\
    %Batatas & 3'500  \\
    %Leite desnatado & 1'250  \\
    %Nabo-sueco & 2'000 & \\
    %Mingau de centeio & 400  \\
    %\midrule
    Total (kcal) & 7'450 \\%& 18'900 \\
    %\end{tabularx} 
    %\end{varwidth}
\end{tcolorbox}
\end{document}
2
  • Is \begin{tcolorbox}[tab2, tabulars={lc},center title,title=Tabela Nutricional Semanal,boxrule=0.75pt, text width=0.5\textwidth] what you are looking for? It will place the footnotes at the bottom of the box Commented Jun 11 at 11:11
  • Yes... but that will require me to adjust the text width every time I have more or less text inside the table, or if I later need to increase font size etc.
    – G. Bay
    Commented Jun 11 at 11:24

0

You must log in to answer this question.

Browse other questions tagged .