
我使用包“color”來創建一個帶有黑色文字的綠色文字框,我的程式碼是 -
\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
or一樣\mbox
,並且形成一個水平(LR)盒子,所以你需要
\textbf{\fcolorbox{black}{green!30}{%
\parbox{3cm}{black text on a boxed green background}}}
替換3cm
為您需要的任何寬度。