标题中的 longtabu + 圆角框

标题中的 longtabu + 圆角框

这个问题是如何结合 mdframed 和 tabu

我有很多行,它无法与 tabluarx 配合使用。我想在 longtable 或 longtabu 的标题行周围显示这个圆角框。

例子:

\documentclass[a5paper,10pt]{article}
\usepackage[many]{tcolorbox}
\usepackage{array,tabularx}
\usepackage{colortbl}
\usetikzlibrary{calc}

\newcommand{\Repeat}[2]{% \repeat already defined
    \foreach \n in {1,...,#1}{#2}
}

\tcbset{enhanced jigsaw,
        boxrule=0pt,
        fonttitle=\bfseries\large,
        fontupper=\normalsize\sffamily,
        colback=white,colframe=white,
        overlay={
          \draw[preaction={fill=gray!40},rounded corners=2mm,thick]
               (frame.north west) rectangle
                     ($(frame.north east) + (0,-1.25\baselineskip)$);
    }
}

\newcolumntype{R}{>{\raggedleft\arraybackslash}p{1cm}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}

\begin{tcolorbox}[tabularx*={\arrayrulewidth0mm}{XC{2cm}RRR}]
\textbf{Name} & \textbf{Date} & \textbf{Price} & \textbf{Qty} & \textbf{Total}\\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
LAST &  9999-99-99 & 999 & 9 & 99999 \\

\end{tcolorbox}

\end{document}

在此处输入图片描述

我需要在这里使用 longtable 或 longtabu。而 tcolorbox 不能与 longtable 或 longtabu 一起使用。我现在正在考虑使用 tikz 绘制标题单元格的背景,但不确定如何操作。

更新:

\begin{longtabu} {cc}
\boxedheader{ \textbf{D1} & \textbf{D2} }
2014-01-01 & 2014-01-01 \\
2014-01-01 & 2014-01-01 \\
\end{longtabu}

结果:

在此处输入图片描述

可能的解决方法是创建具有不可见内容的虚假列:

\setlength{\tabcolsep}{1pt}
\begin{longtabu} {lcp{12pt}cr}
\boxedheader{ & \textbf{D1} & & \textbf{D2} & }
& 2014-01-01 & & 2014-01-01 & \\
& 2014-01-01 & & 2014-01-01 & \\
\end{longtabu}

在此处输入图片描述

答案1

您可以将tcolorbox其与 一起使用longtabu。但如果表头只需要加框,我建议使用纯tikz解决方案(加上tikzmark):

\documentclass[a5paper,10pt]{article}
\usepackage{array,tabularx,longtable,tabu}
\usepackage{colortbl,tikz}
\usetikzlibrary{calc}
\usetikzlibrary{tikzmark}

\newcounter{headercounter}

\newcommand{\boxedheader}[1]{%
  \stepcounter{headercounter}%
  \begin{tikzpicture}[remember picture]
  \path[thick,rounded corners=2mm,draw=black,fill=gray!40!white,overlay]
    (-0.2,-0.25\baselineskip) rectangle ([xshift=2mm,yshift=0.75\baselineskip]pic cs:tableright\roman{headercounter});
  \end{tikzpicture}%
  #1
  \tikzmark{tableright\roman{headercounter}}\\%
}

\begin{document}

\begin{longtabu} to \linewidth {@{}Xcrrr@{}}
\boxedheader{\textbf{Name} & \textbf{Date} & \textbf{Price} & \textbf{Qty} & \textbf{Total}}
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
Some name here &  2014-01-01 & 420 & 2 & 820 \\
LAST &  9999-99-99 & 999 & 9 & 99999 \\
\end{longtabu}

\end{document}

在此处输入图片描述

如果第一个参数不是,则似乎需要X进行绝对定位:\baselineskip

\newcommand{\boxedheader}[1]{%
  \stepcounter{headercounter}%
  \begin{tikzpicture}[remember picture]
  \path[thick,rounded corners=2mm,draw=black,fill=gray!40!white,overlay]
    (-0.2,-0.1) rectangle ([xshift=2mm,yshift=3mm]pic cs:tableright\roman{headercounter});
  \end{tikzpicture}%
  #1
  \tikzmark{tableright\roman{headercounter}}\\%
}

相关内容