在 fcolorbox 中换行文字?

在 fcolorbox 中换行文字?

我正在使用包“颜色”来获得带有黑色文本的绿色文本框,我的代码是 -

\textbf{\fcolorbox{black}{green!30}{black text on a boxed green background}}

请问我怎样才能让它换行呢?

如果不能用“fcolorbox”换行,那么哪个命令可以达到同样的效果并能换行呢?

答案1

我推荐我最喜欢的一个套餐:tcolorbox

\documentclass{article}


\usepackage{tcolorbox}
% A new `\tcbox` command



\newtcbox{\highlight}[0]{boxsep=0pt,left=0pt,top=0pt,bottom=0pt,right=0pt,boxrule=0pt,arc=0pt,auto outer arc,colback=green,width=6cm}


\begin{document}

\highlight{black text on a boxed green background}

\begin{tcolorbox}[width=6cm,colback=green]
black text on a boxed green background
\end{tcolorbox}

\begin{tcolorbox}[width=6cm,colback=green,boxrule=5pt]
black text on a boxed green background
\end{tcolorbox}

\begin{tcolorbox}[width=6cm,colback=green,arc=0pt,auto outer arc]
black text on a boxed green background
\end{tcolorbox}


\end{document} 

在此处输入图片描述

答案2

\fcolorbox类似于\fbox\mbox并构成一个水平(LR)框,因此您需要

\textbf{\fcolorbox{black}{green!30}{%
   \parbox{3cm}{black text on a boxed green background}}}

替换3cm为您所需的任何宽度。

相关内容