Is there an environment or package I can use to make text always visible on a beamer presentation (with photo backgrounds)? How can one ensure a 'high contrast text colour depending on the background'? (thanks @percusse)

Another way to ask this how can I make the text auto-adjust colour for optimum readability depending on it's surroundings and background?

Let's say I have a photo as a background, how can I make text pixel aware of it's surroundings and have it become lighter on the darker part of an image background and darker on the lighter parts of a background.

In instances where you have a rapid gradient (sharp or sudden white to black), the text should be outlined or some adjustment should be made to keep text readable.

An example might be pulling random photos into as frame backgrounds and not having to worry about self-adjusting and tweaking every frame for readability.

Some have suggested that content should always be the most important thing, which I understand, but that is not the issue here.

An example image (stolen from this page) enter image description here

It might also be usable if the package specifies ranges so that colour adjustment can happen as in this picture:

enter image description here

Another example would be where we have a black to white (left to right) gradient in a picture. Layering text on this would have the text respond in the opposite gradient direction white to black (left to right). This would make the text readable regardless of where it is.

Is there a way to do this in beamer/LaTeX? Maybe the presentation and visual experts can give me a phrase or a word for what I'm looking for here.

  • 1
    No expert here but I think you are looking for high contrast text color depending on the background. However, how can one obtain the histogram of the background and select the proper color scheme in a PDF file I have no idea. Maybe branching off to Phyton or Lua before you include the background picture might help.
    – percusse
    Jul 29, 2013 at 20:51
  • Exactly, I was hoping something like this exists already. Question updated. Jul 30, 2013 at 7:04
  • 1
    I voted to close this question since it seem impossible to solve with LaTeX …
    – Tobi
    Nov 5, 2013 at 12:49
  • 1
    I guess this question can’t be answered since it seems impossible with LaTeX …
    – Tobi
    Nov 5, 2013 at 12:49
  • 1
    Regarding the goal of readability: one could think of using the technique mouse pointers on screens and subtitles in movies use: black/dark with a white contour (outline?) (or the contrary). LaTeX has e.g. the contour package.
    – benjamin
    Jun 3, 2022 at 9:36

2 Answers 2


I’d say it is impossible with LaTeX only. At least you must call some other programs in the background but even this will be to complex I guess. So prepare the images with a software like Inkscape or adobe illustrator and export the image with the text as PDF to use it in LaTeX.


(A little long for a comment …)

I’m not sure if this is a good idea. Assume you got several pictures with different colors, then you’ll get very different text colors on each slide and loose the connection between the slides and it won’t be e consistent design. In case of background images the effect can be even counterproductive: If the background changes from slide to slide the audience will wonder why rather than listening to you and if the background is to complex it will catch more attention that it deserves. Certainly the background can make a presentation nicer but the fore ground (i.e. text on slides, your speaking etc.) is much more important ;-)

Sure “matching colors with each picture” or “using high contrast colors” can be a design rule and work very well for some applications But I’m convinced that in this case no computer would find the really matching colors. Even if they are (mathematically) in contrast to the image, a human (designers) eye only find the colors that to the job. it’s never a good idea to let a computer do the design …

An idea for captions on images

If you want to place a (caption) text on an image, which is not a background, I suggest to use a (white) background to all images captions. You can use TikZ To add the text, or create a new command, like \captionedimage{<caption>}[<options>]{<image>}:




% define backgroundcolors

% using xparse to define the new command
\NewDocumentCommand{\captionedimage}{ m O{} m }{%
        % include the image in a node
        \node (graphic) [inner sep=0pt] {\includegraphics[#2]{#3}};
        % draw the node for the number
        \node (number) [%
            below right=1mm of graphic.north west,
            minimum width=3em,
            minimum height=5.4ex] {\thefigure};
        % draw the node with the caption
        \node [%
            right=-0.5pt of number.north east,
            anchor=north west,
            text width=12em,
            minimum height=5.4ex] {#1};

    \title{Captioned images}
        \captionedimage{Caption Text}[width=\textwidth]{example-image}
            {A very long caption Text. A very long caption Text.}
        \captionedimage{Caption Text}[width=\textwidth]{example-image-b}

I just borrowed the color theme of TeX.SX, but it would be much better to define the colors according to the beamer color theme …

  • Thanks for the extended answer and example @Tobi, I've learned quite a few new things here. I don't know either if this is a good design idea or not, but have seen it more frequently in a lot of online and industry presentations. The idea however is to not deviate too far from existing slides - to be able to use old/existing slides (standard frames, that would just have high contrast text depending on the background), just with more interesting backgrounds (maybe more 'punchy' for students?). Jul 30, 2013 at 17:57
  • 1
    @ForkrulAssail: I extended my answer a little, and I claim that it’s is impossible to get satisfying results with an automatic computer based approach. Maybe you can show more examples, but I’m sure that they are hand-made …
    – Tobi
    Jul 30, 2013 at 19:27
  • thanks again for your attempt, yet this doesn't solve my problem. The whole point would be not to have a caption area but 1) have the text colour be adjusted (by the character if need be), 2) have this happen automatically depending on the background image's locational colour. Nov 5, 2013 at 12:42
  • I know, but I’d say it is impossible to do it in TeX. Tex isn’t an image processor ;-) So if you want to use TeX you must use another solution for example the on I posted as an answer or you must use another software …
    – Tobi
    Nov 5, 2013 at 12:47

You must log in to answer this question.

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