# Removing all table border margins

I have a macro that generates a Latex table, which I need to fit inside a box (well, a Label) in Asymptote. I would like to have the bounding box edges coincide with the table edges. This does not happen because of the table border margins, as shown in the code below.

\documentclass{article}

\usepackage{tabularx}
\usepackage[table]{xcolor}

\definecolor{lightOrange}{HTML}{FFD993}
\begin{document}

\fcolorbox{red}{gray}{%
\begin{minipage}{5cm}%
\begin{tabularx}{5cm}{|X|}%
\hline
\cellcolor{lightOrange} Some text\\
\hline
\end{tabularx}
\end{minipage}}%

\end{document}


Is there a way to remove all the margins around the table so that it perfectly fits the minipage?

I can remove the top and bottom margins using something like \vspace*{-3pt}, but it does not seem very elegant, and still leaves the left and right margins.

I guess that's the desired result:

two changes are necessary:

• tabularx˛ size had to be equal tominipage size. the simplest way to achieve this is determine size with \linewidth
• \fboxsep has to be set to zero:

\documentclass{article}
\usepackage{tabularx}
\usepackage[table]{xcolor}
\definecolor{lightOrange}{HTML}{FFD993}

\begin{document}
\setlength\fboxsep{0pt}
\fcolorbox{red}{gray}{%
\begin{minipage}{5cm}%
\begin{tabularx}{\linewidthe}{X}
\cellcolor{lightOrange} Some text\\
\end{tabularx}%
\end{minipage}%
}
\end{document}

• purpose of use tabularx in \minipage is not known, however the same result is possible to achieve on the simpler way by use of the tcolorbox package:

\documentclass{article}
\usepackage[many]{tcolorbox}
\definecolor{lightOrange}{HTML}{FFD993}

{
width=#1,
colback=lightOrange,
colframe=red,
sharp corners
}
\usepackage{lipsum}

\begin{document}
\lipsum*[11]
\end{document}

• I need to use tabularx because the macro actually builds a table. The code I provided was just an example with one cell in the table. – Jrenard Mar 14 '18 at 17:40
• you can insert table in tcolorbox, even more tcolorbox package provide special box for tabularx – Zarko Mar 14 '18 at 18:04

Needless to use a tabular(x): a simple \parbox{5cm}will do, withe optional arguments to control haight and position:

\documentclass{article}
\usepackage[table]{xcolor}

\definecolor{lightOrange}{HTML}{FFD993}

\begin{document}

\fboxrule = 1pt
\fcolorbox{red}{lightOrange}{%
\parbox[c][3ex]{5cm}{ Some text}%
}%

\end{document}
`