1

I need a tcolorbox with a longtable inside but I can't adjust the right margin.

Actually, I want a rounded title and a frame with a breakable table which could be placed at any place of the page.

Note: I'm already tried every 0pt option that I've found but it doesn't seem enough ...

Example:

enter image description here

Code:

\documentclass[a4paper,11pt]{report}

\usepackage[table]{xcolor} %colr
\usepackage[raster,skins]{tcolorbox} %textbox
\usepackage{setspace}
\usepackage{longtable}

\usepackage[left=2.5cm, right=2cm, bottom=1cm]{geometry}
\tcbuselibrary{listings,breakable}

\begin{document}%\layout

\vspace*{550px}


\setlength{\LTpre}{0pt}
\setlength{\LTpost}{0pt}
\setlength{\LTleft}{0pt}
\setlength{\LTright}{0pt}

\tcbset{
    breakable,  enhanced,   
    left*=0pt,right*=0pt,
    top=0pt,bottom=0pt,
    toptitle=0mm, bottomtitle=0mm,
    boxsep=0pt,left=0pt,right=0pt,
    boxrule=2pt, % NO EFFECT
}

\begin{tcolorbox}\textsl{•}[title=\strut\textsc{This is a colorbox}]
\begin{longtable}[]{l|p{0.4\textwidth}|p{0.4\textwidth}|l}

    \multicolumn{4}{c}{\cellcolor{black}\color{white} \textbf{\textsc{This is the table header}} } \\ \hline
    1 & text description & second text & date \\ \hline
    2 & text description &  second text & date \\ \hline
    3 & text description &  second text & date \\ \hline
    4 & text description &  second text & date \\ \hline
    5 & text description &  second text & date \\ \hline
    6 & text description &  second text & date \\ \hline
    7 & text description &  second text & date \\ \hline
    8 & text description &  second text & date \\ \hline
    9 & text description &  second text & date \\ \hline
    11 & text description &  second text & date \\ \hline
    12 & text description &  second text & date \\ \hline
    13 & text description &  second text & date \\ \hline
    14 & text description &  second text & date \\ \hline
    15 & text description &  second text & date \\ \hline 
\end{longtable}
\end{tcolorbox}

\end{document}

What is the problem with this code? Is there another alternative?

1 Answer 1

1

Your tabular is just not wide enough, since the widths of all columns added together don't add up to \textwidth.

To simplify the calculation of the correct widths, you could make use of the X column type provided by the xltabular package, that will stretch to the remaining space. If you wish to use a longtable, you should use the package xltabular that combines the longtable and the tabularx packages.

\documentclass[a4paper,11pt]{report}

\usepackage[table]{xcolor} %colr
\usepackage[raster,skins]{tcolorbox} %textbox
\usepackage{setspace}
\usepackage{xltabular}

\usepackage[left=2.5cm, right=2cm, bottom=1cm]{geometry}
\tcbuselibrary{listings,breakable}

\begin{document}%\layout

\vspace*{550px}

\setlength{\LTpre}{0pt}
\setlength{\LTpost}{0pt}
\setlength{\LTleft}{0pt}
\setlength{\LTright}{0pt}

\tcbset{
    breakable, enhanced,   
    left*=0pt, right*=0pt,
    top=0pt, bottom=0pt,
    toptitle=0mm, bottomtitle=0mm,
    boxsep=0pt, left=0pt, right=0pt,
    boxrule=2pt, % NO EFFECT
}

\begin{tcolorbox}[title=\strut\textsc{This is a colorbox}]
\begin{xltabular}{\textwidth}{l|p{0.3\textwidth}|p{0.3\textwidth}|X}
    \multicolumn{4}{c}{\cellcolor{black}\color{white} \textbf{\textsc{This is the table header}} } \\ \hline
    1 & text description & second text & date \\ \hline
    2 & text description &  second text & date \\ \hline
    3 & text description &  second text & date \\ \hline
    4 & text description &  second text & date \\ \hline
    5 & text description &  second text & date \\ \hline
    6 & text description &  second text & date \\ \hline
    7 & text description &  second text & date \\ \hline
    8 & text description &  second text & date \\ \hline
    9 & text description &  second text & date \\ \hline
    11 & text description &  second text & date \\ \hline
    12 & text description &  second text & date \\ \hline
    13 & text description &  second text & date \\ \hline
    14 & text description &  second text & date \\ \hline
    15 & text description &  second text & date \\ \hline 
\end{xltabular}
\end{tcolorbox}

\end{document}

enter image description here

You must log in to answer this question.

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