3

This is related to Vary transparency of colorbox in a sentence

I would like to have a transparent colorbox for some overlay and this attempt is not working

\documentclass{article}

\usepackage{soul,xcolor}
\usepackage{transparent}
\sethlcolor{red}
\begin{document}

\hl{This is}%
\transparent{0.1}{\hl{\hspace{5cm}}}%

\end{document}
4
  • What is it you are trying to achieve? In other words, what is the result supposed to look like? – Steven B. Segletes May 2 at 18:54
  • Note: \hl{\hspace{5cm}} does not appear to valid syntax, even in the absence of the transparent package. – Steven B. Segletes May 2 at 19:20
  • The result is supposed to look like a "yellow" 5cm semitransparent rectangle – Ruth Lazkoz May 3 at 9:30
  • Since you cannot use \hspace in the \hl argument, perhaps an alternative is to use a \rule, as I show in my answer. You can adjust the rule depth and height to suit. – Steven B. Segletes May 3 at 9:45
1

I point out that

\hl{\hspace{5cm}}}

produces an error, regardless of the use of transparency. However, one can use a \rule to achieve a blank field and with the added use of \transparent, that colored rule field can become transparent.

After some confusion on my part seemingly related to multiple compilations required for the transparent package, it seems to work.

Take this MWE:

\documentclass{article}

\usepackage{soul,xcolor}
\usepackage{transparent}
\sethlcolor{red}
\begin{document}

\leavevmode
\rlap{hi mom how are you?}%
\transparent{.6}{\hl{xyz}\color{yellow}\rule{1in}{2ex}}
\end{document}

I get something that looks like I would expect.

enter image description here

If I change the \transparent parameter to .1 and perform the requisite numbers of compilations, the result changes to

enter image description here

which also follows what the package is apparently supposed to do. As the transparency approaches unity, the red and yellow fields become opaque.

5
  • 1
    You have to compile twice, transparent uses the aux-file. – Ulrike Fischer May 3 at 7:02
  • 1
    @UlrikeFischer I should have mentioned that it made no difference in my example...though I will have to check that MikTeX wasn't auto-cleaning out the aux file. – Steven B. Segletes May 3 at 9:04
  • 1
    @UlrikeFischer It is not cleaning out the aux. Therefore, I stand by my report. – Steven B. Segletes May 3 at 9:12
  • 2
    well it works for me, and it is curious that you use 0 for opaque, that should be 1. Can you show your log-file? And how do you compile? – Ulrike Fischer May 3 at 9:26
  • @UlrikeFischer Now I am the one confused. All of a sudden, I can't recreate the problem. I am going to eliminate such talk from my answer unless and until I can figure out what I was doing. wrong. – Steven B. Segletes May 3 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.