# How to make \colorbox fill the color between underline and overline of a text?

I want the \colorbox to fill the content between underline and overline of a text. How can i achieve this?

Currently, i use

$\overline{\underline{\colorbox{light-gray}{\makebox [\textwidth][l]{\bfseries \color{black} HELLO}}}}$


But, this leaves a gap between the colorbox and the underline/overline

Here is a way, with tabularx:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}%
\usepackage{tabularx, boldline}
\usepackage[svgnames, table]{xcolor}

\begin{document}

\noindent\begin{tabularx}{\linewidth}{>{\bfseries\rule{0pt}{2.5ex}\columncolor{Lavender!60!lightgray}}X}
\hlineB{2} HELLO\\
\hlineB{2}
\end{tabularx}

\end{document}


A way with tcolorbox and setting up a very configurable tcbox:

\documentclass[11pt]{article}

\usepackage[most]{tcolorbox}
\newtcbox{\colorboxouline}[1][]{boxsep=0.5pt,top=1pt,bottom=1pt,colframe=black,colback=gray,boxrule=0pt,toprule=3pt,bottomrule=3pt,sharp corners, enhanced jigsaw,,#1}

\begin{document}
\colorboxouline{Test}

\end{document}


\colorbox will color its content, and does so. To color the \overline and \underline, you need to add them as the content inside the \colorbox. I've also changed $ into $$ and $$, see Are $$ and $$ preferable to $?

Output

Code

\documentclass[11pt]{article}
\usepackage{xcolor}
\usepackage{mathtools}
\begin{document}

\colorbox{gray}{$$\overline{\underline{\text{\bfseries\color{black}test}}}$$}
\end{document}