嗨,我确信这是一个非常基本的问题,但是有没有办法告诉\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}