# Tabularx, tcolorbox and spacing: how to remove the empty line?

Consider the following example, inspired from the previous post here:

\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}


There is a one line spacing before or after the table depending on where the title is positioned. How to remove this spacing (while keeping the possibility to put the title at the top or at the bottom of the tcolorbox?

• Remove the {xshift=..., yshift= ...} statement – user31729 Oct 3 '17 at 16:18
• @ChristianHupfer suggestion does solve the problem. Is this question candidate to be closed as off-topic? – Cragfelt Dec 23 '17 at 9:12
• @Cragfelt: My suggestion does solve the problem, but I had no time to investigate the reason. Keep it open, I'll try to find out – user31729 Dec 23 '17 at 9:51
• @ChristianHupfer Ok that is your call. But I still thinking that question is solved, since the OP was asking just "how to remove the empty line?". – Cragfelt Dec 23 '17 at 9:57
• @Cragfelt: Found a 'solution' or 'explanation'. Looks like a bug to me, but I am unsure. – user31729 Dec 23 '17 at 11:03

The reason for the additional spacing above (or below) the table is that yshift does not keep yshifttext from being non-zero. yshifttext seems to have the value of height of the boxed title. Perhaps this is a bug of tcolorbox.

A solution is either to set yshifttext=0pt or yshift*=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}