如何使 tcolorbox 在页面中水平居中?

如何使 tcolorbox 在页面中水平居中?

我想将tcolorbox置于宽度小于 的页面(或列等)的中心\linewidth

tcolorbox有没有比将 嵌套在 中更好的方法\begin-\end{center}

\documentclass{article}

\usepackage{multicol}
\usepackage{tcolorbox}
\usepackage{lipsum}

\begin{document}
\begin{multicols}{2}
I would like the following box to be centered in the column. Here is a direct way to do it, instead of using \verb+\begin-\end{center}+?
\begin{tcolorbox}[width=0.75\linewidth]
This is a test.
\end{tcolorbox}
\lipsum[2]
\end{multicols}
\end{document}

enter image description here

答案1

添加选项center

enter image description here

\documentclass{article}

\usepackage{multicol}
\usepackage{tcolorbox}
\usepackage{lipsum}

\begin{document}
\begin{multicols}{2}
I would like the following box to be centered in the column. Here is a direct way to do it, instead of using \verb+\begin-\end{center}+?
\begin{tcolorbox}[width=0.75\linewidth, center]
This is a test.
\end{tcolorbox}
\lipsum[2]
\end{multicols}
\end{document}

enter image description here

相关内容