Tabularx、tcolorbox 和 Spacing:如何删除空行?

Tabularx、tcolorbox 和 Spacing:如何删除空行?

考虑以下示例,灵感来自上一篇文章这里

\documentclass[a4paper, 10pt]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{array}
\usepackage[table]{xcolor}
\usepackage[skins,theorems,breakable,most]{tcolorbox}

\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{tabularx}
\usepackage{multicol}

\NewDocumentCommand{\tcbtab}{O{}m+m}{%
  \begin{tcolorbox}[%
    enhanced,
    sharp corners,
    titlerule = 0pt,
    boxsep=0pt,
    left=0pt,
    right=0pt,
    top=0pt,
    bottom=0pt,
    middle=0pt,
    colframe = black,
    box align=center,
    halign=center,
    valign=center,
    boxed title style={
      enhanced,
      colback = black,
      arc=0pt,
      outer arc=0pt,
    },
    listing only,
    title = {\centering\makebox[\linewidth][c]{#2}},%
    #1%
    ]
    #3%
    \end{tcolorbox}%
}

\begin{document}
\lipsum[1]
\tcbtab[
    attach boxed title to top={xshift=0mm,yshift=0mm},%
    tabularx={X|p{2cm}}%
]{Title}{%
First column & Second column \\
\hline
Cell 1 & Cell 2
}
\lipsum[1]
\tcbtab[
    attach boxed title to bottom={xshift=0mm,yshift=0mm},%
    tabularx={X|p{2cm}}%
]{Title}{%
First column & Second column \\
\hline
Cell 1 & Cell 2
}
\end{document}

表格前或表格后有一行间距,具体取决于标题的位置。如何删除此间距(同时保留将标题放在表格顶部或底部的可能性tcolorbox

在此处输入图片描述

答案1

表格上方(或下方)有额外间距的原因是yshift不保持yshifttext非零值。yshifttext似乎具有带框标题的高度值。 也许这是 的一个错误tcolorbox

解决方案是设置yshifttext=0ptyshift*=0mm

\documentclass[a4paper, 10pt]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{array}
\usepackage[table]{xcolor}
\usepackage[skins,theorems,breakable,most]{tcolorbox}

\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{tabularx}
\usepackage{multicol}

\NewDocumentCommand{\tcbtab}{O{}m+m}{%
  \begin{tcolorbox}[%
    enhanced,
    sharp corners,
    titlerule = 0pt,
    boxsep=0pt,
    left=0pt,
    right=0pt,
    top=0pt,
    bottom=0pt,
    middle=0pt,
    colframe = black,
    box align=center,
    halign=center,
    valign=center,
    boxed title style={
      enhanced,
      colback = black,
      sharp corners,
    },
    %listing only,
    title = {\centering\makebox[\linewidth][c]{#2}},%
    #1%
    ]%
    #3%
    \end{tcolorbox}%
}

\begin{document}
\lipsum[1]
\tcbtab[
attach boxed title to top={yshift=0mm,yshifttext=0pt},%
tabularx={X|p{2cm}}%
]{Title}{%
First column  &Second column \\
\hline
Cell 1 & Cell 2
}
\lipsum[1]
\tcbtab[
attach boxed title to bottom={xshift=0mm,yshift*=0mm},%
tabularx={X|p{2cm}}%
]{Title}{%
  First column & Second column \\
  \hline
  Cell 1 & Cell 2 
}
\end{document}

在此处输入图片描述

相关内容