0

I'm trying to make a command that creates a box as seen in the picture below:

enter image description here

I've used minibox but the results aren't exactly the same. Here's what I've done:

\definecolor{mycolor}{gray}{.90}
\newcommand{\myCommand}[1]{{\textwidth}\colorbox{mycolor}
   {\begin{minipage}
   {\textwidth}\colorbox{black}{\textcolor{white}{\textsc{#1}}}
   \end{minipage}}}
    

\begin{document}

   \myCommand{1}{Test}

    
\end{document}

And here's the result:

enter image description here

The black box in my case is a bit smaller than the height of the gray. How can I make them the same size? Any ideas are welcome, it's not necessary to use minipage I just couldn't think of anything else.

Thanks in advance!

1 Answer 1

0

See if the following redefinition of your command is what you after. It consider that in gray box is only one line text or no text.:

\usepackage{xcolor}
\usepackage{linegoal}

\newlength{\boxwidth}

\newcommand{\myCommand}[2]%
{\noindent%
\colorbox{black}{\textcolor{white}{\vphantom{Xp}\textsc{#1}}}%
\colorbox{gray!90}{\parbox[t]{\linegoal}{\vphantom{Xp}#2}\hspace{-\fboxsep}}\smallskip%
}


\begin{document}
   \myCommand{123}{ana}
\end{document}

enter image description here

(red lines indicate text borders)

1
  • Excellent! Thank you very much! Feb 14, 2022 at 14:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .