[Tex/LaTex] tcolorbox & text vertically center align

tcolorboxvertical alignment

tcolorbox and text does not vertically align to the center with one another.

\documentclass{book}

\usepackage{tcolorbox}% for framed rounded boxes
\tcbset{colframe=black,colback=white,colupper=black,
fonttitle=\bfseries,nobeforeafter,center title,size=small}

\begin{document}

\tcbox{1}, \tcbox{2}, ... ,\tcbox{9} -- numbers\\
\tcbox{$+$}, \tcbox{$-$}, \tcbox{$\times$}, \tcbox{$\div$} -- operators\\
\tcbox{$(-)$} -- negative sign\\
\tcbox{$=$} or \tcbox{\sc{Enter}} -- equal sign\\

\end{document}

text align

As can be seen, the text is aligned to the bottom.
How do I make both of them align next to one another?

Best Answer

You have to use the option box align=base (or tcbox raise base, which is equivalent) in your \tcbset.

MWE

\documentclass{book}

\usepackage{tcolorbox}% for framed rounded boxes
\tcbset{colframe=black,colback=white,colupper=black,
fonttitle=\bfseries,nobeforeafter,center title,size=small,box align=base}

\begin{document}

\tcbox{1}, \tcbox{2}, ... ,\tcbox{9} -- numbers

\tcbox{$+$}, \tcbox{$-$}, \tcbox{$\times$}, \tcbox{$\div$} -- operators

\tcbox{$(-)$} -- negative sign

\tcbox{$=$} or \tcbox{\sc{Enter}} -- equal sign

\end{document} 

Output

enter image description here

P.S. Don't use \\ to start a new paragraph, but either a blank line or \par.


EDIT

If you need this behavior only for some of the boxes, assign that property locally instead of globally. This means to remove the option from your \tcbset and set it for the boxes where it is needed, e.g.

\tcbox[tcbox raise base]{$(-)$}

MWE

\documentclass{book}

\usepackage{tcolorbox}% for framed rounded boxes
\tcbset{colframe=black,colback=white,colupper=black,
fonttitle=\bfseries,nobeforeafter,center title,size=small}

\begin{document}

\tcbox[tcbox raise base]{1}, \tcbox{2}, ... ,\tcbox{9} -- numbers

\tcbox{$+$}, \tcbox{$-$}, \tcbox{$\times$}, \tcbox{$\div$} -- operators

\tcbox[tcbox raise base]{$(-)$} -- negative sign

\tcbox{$=$} or \tcbox{\sc{Enter}} -- equal sign

\end{document} 

Output

enter image description here

Related Question