设置 fcolorbox 的宽度

设置 fcolorbox 的宽度

嗨,我确信这是一个非常基本的问题,但是有没有办法告诉\fcolorbox我们xcolor绘制一定宽度的框。

例如\fbox我会这样做

\documentclass{article}
\usepackage{xcolor}
\begin{document}
\framebox[1in]{text}

\fcolorbox{blue}{blue!40}{what do I do here?}

\end{document}

答案1

没有\framecolorbox宏,但你可以轻松地构建一个xparse

\usepackage{xparse}
\NewDocumentCommand{\framecolorbox}{oommm}
 {% #1 = width (optional)
  % #2 = inner alignment (optional)
  % #3 = frame color
  % #4 = background color
  % #5 = text
  \IfValueTF{#1}
   {\IfValueTF{#2}
    {\fcolorbox{#3}{#4}{\makebox[#1][#2]{#5}}}
    {\fcolorbox{#3}{#4}{\makebox[#1]{#5}}}%
   }
   {\fcolorbox{#3}{#4}{#5}}%
 }

完整示例:

\documentclass{article}
\usepackage{xcolor}
\usepackage{xparse}
\NewDocumentCommand{\framecolorbox}{oommm}
 {% #1 = width (optional)
  % #2 = inner alignment (optional)
  % #3 = frame color
  % #4 = background color
  % #5 = text
  \IfValueTF{#1}
   {%
    \IfValueTF{#2}
     {\fcolorbox{#3}{#4}{\makebox[#1][#2]{#5}}}
     {\fcolorbox{#3}{#4}{\makebox[#1]{#5}}}%
   }
   {\fcolorbox{#3}{#4}{#5}}%
 }

\begin{document}
\framecolorbox{blue}{blue!40}{what do I do here?}

\framecolorbox[4cm]{blue}{blue!40}{what do I do here?}

\framecolorbox[4cm][l]{blue}{blue!40}{what do I do here?}

\framecolorbox[4cm][r]{blue}{blue!40}{what do I do here?}

\framecolorbox[4cm][s]{blue}{blue!40}{what do I do here?}
\end{document}

在此处输入图片描述

相关内容