[Tex/LaTex] How to keep transparent fcolor box

boxescolortransparency

I am using \fcolorbox on a background that is itself colored; I don't need color inside the box, and I want its background to be transparent so that the background color shows through. The transparent package does not seem to work for this. How can I draw a transparent color?

Best Answer

In my ytableau package I sort of dealt with this question in the following way. Basically, my idea is that uncolored text (such as text produced by TeX in normal paragraphs) actually already has a transparent background, which shows up as white only because the default paper color is white. xcolor seems to actually "paint" a color in the background of any colored box, so even making a "white" \fcolorbox makes it an opaque white. This makes sense if you imagine putting such a box on top of another box that had been colored something else. As such, to draw a transparent box you need to not use \fcolorbox, but simply \fbox.

This has two deficiencies:

  • You have to use two different commands depending on whether or not you want color. This is, of course, how things usually are, but if you really want unity you will have to redefine \fcolorbox (or better, define your own colored-box command) that interprets, say, "clear" to mean \fbox. Since \fcolorbox has a number of optional arguments I feel this is more trouble than it is worth.

  • You can't color the frame of the \fbox alone. One way to do this is to put \color{<frame color>} before \fbox and then put \color{<text color>} inside \fbox, which is necessary to override the frame color for the text itself. Even if you want the text to be the default black.

For example, here is a "color-framed colored-text box":

\newcommand\colorfbox[3]{%
 {\color{#1}\fbox{\color{#2}#3}}%
}
\colorfbox{red}{black}{abc} def