tcolorbox & 文字垂直居中對齊

tcolorbox & 文字垂直居中對齊

tcolorbox 和文字彼此不垂直居中對齊。

\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}

文字對齊

可以看到,文字與底部對齊。我怎樣才能使它們兩者並排對齊?

答案1

您必須box align=basetcbox raise base.\tcbset

微量元素

\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} 

輸出

在此輸入影像描述

PS 不要用它\\來開始一個新段落,而是用一個空行或\par.


編輯

如果您只需要對某些框執行此行為,請在本機而不是全域指派該屬性。這意味著從您的選項中刪除該選項\tcbset並將其設定為所需的框,例如

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

微量元素

\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} 

輸出

在此輸入影像描述

相關內容