5

I use the memoir class to produce a children's poetry book. To make it more engaging for the readers, I rely on the background package to include pictures that cover the entire page.

Sometimes text readability is poor if the background image interferes with it. In that case, I edit the image and move some of its elements, iterating until the result looks good. However, this process must be redone when verses are shuffled around or if font-sizes are changed. Here's an example of such an issue:

Poor contrast because of the background image

I am in search of a "focus on content, not presentation" way to do it, and I imagine that placing a shape between the background and the text could address the problem. I envision something like this, where I can adjust the opacity of the shape and blur its edges:

A shape between the background image and the text

How can this be accomplished with LaTeX, in a way that the shape's size is automatically adjusted whenever the text changes? I would also be happy with solutions that are not fully automated, but which work entirely within LaTeX and remove the need to edit the image itself.

Here is a minimal example that reproduces the issue:

\documentclass[14pt]{memoir}
\usepackage[pages=some]{background}

\begin{document}

\PlainPoemTitle
\PoemTitle{Lo Remipsum}

\begin{verse}[\versewidth]
one two three four \\
one two three four \\
one two three four \\
one two three four.
\end{verse}



\backgroundsetup{scale = 1,
angle = 0,
opacity = 1,
contents = {\includegraphics[
    width = \paperwidth,
    height = \paperheight]
    {example-image-a}}}\BgThispage
\end{document}

And here is an actual example from the book. The current workaround is to reduce the opacity of the background such that the contrast is tolerable. But ideally, the image should not look so pale, except under the text.

Text above image, poor contrast

2 Answers 2

5

Another possibility (but requiring a lot of manual twiddling...) is to print the text in a rectangle with a white filling of a given transparency. For example, using TikZ:

\documentclass[14pt]{memoir}
\usepackage[pages=some]{background}
\usepackage{tikz}

\begin{document}

\PlainPoemTitle
\PoemTitle{Lo Remipsum}

\hspace{8cm}\tikz \node[text width=5cm, fill=white, fill opacity=0.7, text opacity=1]{
    one two three four \\
    one two three four \\
    one two three four \\
    one two three four.
};

\backgroundsetup{scale = 1,
angle = 0,
opacity = 1,
contents = {\includegraphics[
    width = \paperwidth,
    height = \paperheight]
    {example-image-a}}}\BgThispage
\end{document}

enter image description here

It works much better if the background picture has a white background.

To blur the edge, I can use circular shading; I, unfortunately, have no idea how to define a "rectangular shading" like the one you show in the example, but probably it's possible.

\documentclass[14pt]{memoir}
\usepackage[pages=some]{background}
\usepackage{tikz}
\usetikzlibrary{fadings}

\pgfdeclareradialshading{myfadingraw}{\pgfpointorigin}{
  color(0pt)=(pgftransparent!30); color(21bp)=(pgftransparent!30);
  color(25bp)=(pgftransparent!100); color(50bp)=(pgftransparent!100)}%
\pgfdeclarefading{side shaded}{\pgfuseshading{myfadingraw}}%

\begin{document}

\PlainPoemTitle
\PoemTitle{Lo Remipsum}

\hspace{8cm}\tikz \node[text width=4.5cm, fill=white, 
    path fading = side shaded,
    text opacity=1, inner xsep=2cm, inner ysep=0.5cm]{
    one two three four \\
    one two three four \\
    one two three four \\
    one two three four.
};

\backgroundsetup{scale = 1,
angle = 0,
opacity = 1,
contents = {\includegraphics[
    width = \paperwidth,
    height = \paperheight]
    {example-image-a}}}\BgThispage
\end{document}

enter image description here

3

Change the value of the opacity parameter less tha 1, for example opacity=0.4. With this value of opacity You have this result:

enter image description here

2
  • 1
    Thanks for your feedback. This is my current workaround, but it makes the entire image less opaque (as you can see with the cat at the bottom). Ideally, I wish to set the opacity to 1 and apply the wizardry only in the areas where text is present.
    – ralien
    Jan 19, 2023 at 8:42
  • 1
    I think it is very difficult to have the results you hope. In any case try your text in boldface and the 'opacity=.8'. Jan 19, 2023 at 8:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .