1

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

2

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} 

enter image description here

2

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}

enter image description here

1

\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

enter image description here

Code

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.