# A label in color box with fix width and height

I want to have a small size color box with a label in it. This color box should have a fix width and length.

I have tried with \crule[blue]{24mm}{6mm}, which can have the fixed size but I don't know to add a label.

About the \colorbox I tried with following things.But the size changes with the size of label.

\newlength{\DepthReference}
\setlength{\DepthReference}{4pt}%absolute value.
\newlength{\HeightReference}
\setlength{\HeightReference}{4pt}
\newlength{\Width}%

\newcommand{\MyColorBox}[2][blue] {%
\settowidth{\Width}{#2}%
\setlength{\fboxsep}{15pt}%
\colorbox{#1}%
{%
\raisebox{-\DepthReference}%
{%
\parbox[b][\HeightReference+\DepthReference][c]{\Width}{\centering#2}%
}%
}%
}


I want to generate such style and try to keep them in a same line to form a table style.

• Will you again delete this question as soon as you get an answer? – user36296 Jan 31 '19 at 22:04
• @CarLaTeX: If I remember correctly it is possible to delete a question with answer(s) if those have no votes yet – user31729 Feb 1 '19 at 6:45
• Please provide a full, compilable but minimal document (minimal working example, MWE) not just some code lines. This makes it so much easier for others to code a solution and also test it right away. – Martin Scharrer Feb 1 '19 at 10:11
• This should be possible with the adjustbox package, but without a MWE I don't have time to do all the coding right now. – Martin Scharrer Feb 1 '19 at 10:11

You could try with a tcbitemize from tcolorbox. This is just a minimal example to show how it works. You can adjust it to your taste.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lmodern}

\begin{document}
\begin{tcbitemize}[raster columns=4,
sharp corners,
colback=gray!30,
colframe=gray!30, fontupper=\sffamily,
raster equal height=rows, size=small, halign=center, valign=center]

\tcbitem tuple count
\tcbitem[colupper=cyan] sma offset\textsubscript{0}
\tcbitem[colupper=cyan] dict offset\textsubscript{0}
\tcbitem[colupper=cyan] data offset\textsubscript{0}

\tcbitem[colupper=cyan] compression\textsubscript{0}
\tcbitem[colupper=cyan] string offset\textsubscript{0}
\tcbitem sma offset\textsubscript{1}
\tcbitem dict offset\textsubscript{1}

\tcbitem data offset\textsubscript{1}
\tcbitem compression\textsubscript{1}
\tcbitem string offset\textsubscript{1}
\tcbitem[colback=white, colframe=white]\dots

\tcbitem[colback=white, colframe=white]\dots
\tcbitem sma offset\textsubscript{n}
\tcbitem dict offset\textsubscript{n}
\tcbitem data offset\textsubscript{n}

\tcbitem compression\textsubscript{n}
\tcbitem string offset\textsubscript{n}
\tcbitem[colframe=green]min\textsubscript{0}
\tcbitem[colframe=green]max\textsubscript{0}

\tcbitem[raster multicolumn=4, colframe=green]lookup table\textsubscript{0}
\tcbitem[raster multicolumn=4, colframe=green, colback=green, colupper=white, halign=right]Positional SMA index for attribute 0

\end{tcbitemize}
\end{document}


• Ah, you were quicker ... I had a similar idea... +1 from me, just for your idea and in order to prevent the O.P. to delete his question – user31729 Feb 1 '19 at 8:53