我需要一个tcolorbox
有longtable
内部的,但我无法调整正确的利润。
实际上,我想要一个圆形的标题和一个带有可破坏表格的框架,可以放置在页面的任何地方。
注意:我已经尝试了0pt
找到的每个选项但似乎还不够......
例子:
代码:
\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}
这段代码有什么问题?还有其他替代方案吗?
答案1
您的表格不够宽,因为所有列的宽度加在一起不等于\textwidth
。
为了简化正确宽度的计算,您可以使用包X
提供的列类型xltabular
,它将延伸到剩余空间。如果您希望使用longtable
,则应使用xltabular
结合了longtable
和tabularx
包的包。
\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}