2

I've been trying to include a monochromatic PDF vector figure in my LaTeX document and change its fill color directly within LaTeX, without using any external tools. I found two main solutions:

  • Sol1: Setting the PDF color space to RGB and using the decodearray option in \includegraphics. Unfortunately, this method didn't work for me.
  • Sol2: Using TikZ pictures. This method gave me better results but still isn't perfect.

I'm running into two main problems with the TikZ method:

  • Inconsistent Fill Color: Even though I used the same color for the top and bottom borders of the hlines in tblr, the colors of the figure and the \hline don’t look the same.
  • Unwanted Background: The figure has a white background behind it, even though the original figure is black on a transparent background. I set fill=transparent!0 in the TikZ picture, but it didn’t fix the issue.

Any suggestions on how to resolve these issues?

enter image description here Original figure is black (you can download it from here: "left_logo.pdf"). Shown on the right side of the attached image.

Here’s the LaTeX code I’m using:

\documentclass{article}
\usepackage[table, dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{fadings}
\usepackage{tabularray}
\UseTblrLibrary{varwidth} 

\begin{document}

\begin{tikzfadingfrompicture}[name=left]
  \node [fill=transparent!0,draw=none]
  {\includegraphics[width=2.05cm,height=2cm]{./Resources/Figures/left_logo}};
\end{tikzfadingfrompicture}

\begin{titlepage}

  \pagecolor{gray} 
  \begin{tblr}{
    width=\textwidth,
    colspec = {Q[c,2.65cm]X[c]Q[c,2.65cm]},
    rowspec = {Q[b]},
    hlines={1pt, MidnightBlue},
    measure=vbox}
      \fbox{
        \begin{tikzpicture}[
          outer sep=0pt,
          inner sep=0pt,
          baseline=(current bounding box.center)]
            \node[left color=MidnightBlue,right color=MidnightBlue,minimum width=2.16cm,minimum height=1.85cm]{};
            \path[scope fading=left,fit fading=false];
            \node[fill=transparent!0,minimum width=2.16cm+1mm,minimum height=1.85cm+1mm]{};
        \end{tikzpicture}}
      &{
        \textcolor{MidnightBlue}{Lorem ipsum dolor sit amet} \\
        \textcolor{MidnightBlue}{Proin non mauris maximus, pretium} \\
        \textcolor{MidnightBlue}{In convallis eros convallis nunc} \\
        \textcolor{MidnightBlue}{Integer eleifend sit amet risus} \\
        \textcolor{MidnightBlue}{Fusce vulputate ac felis et}
      }&
      \fbox{\includegraphics[width=2.05cm,height=2cm]{./Resources/Figures/left_logo}}
  \end{tblr}

\end{titlepage}

\end{document}

Edit

I forgot to mention that I'm compiling my document with LuaLaTeX.

1 Answer 1

2

You could unset the color of the star so that the included pdf will inherit the colour of the surrounding text.

Following the guide from Changing color in an eps file from within LaTeX one can create the following pdf:

https://github.com/samcarter/shared/blob/main/TeXse/unset.pdf

(the colour was commented out in l.9)

... and then use it like this:

\documentclass{article}
\usepackage[table, dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{fadings}
\usepackage{tabularray}
\UseTblrLibrary{varwidth} 

\begin{document}

\begin{titlepage}

  \pagecolor{gray} 
  \begin{tblr}{
    width=\textwidth,
    colspec = {Q[c,2.65cm]X[c]Q[c,2.65cm]},
    rowspec = {Q[b]},
    hlines={1pt, MidnightBlue},
    measure=vbox}
      \fbox{\color{MidnightBlue}\includegraphics[width=2.05cm,height=2cm]{unset}}
      &{
        \textcolor{MidnightBlue}{Lorem ipsum dolor sit amet} \\
        \textcolor{MidnightBlue}{Proin non mauris maximus, pretium} \\
        \textcolor{MidnightBlue}{In convallis eros convallis nunc} \\
        \textcolor{MidnightBlue}{Integer eleifend sit amet risus} \\
        \textcolor{MidnightBlue}{Fusce vulputate ac felis et}
      }&
      \fbox{\includegraphics[width=2.05cm,height=2cm]{left_logo}}
  \end{tblr}

\end{titlepage}

\end{document}

enter image description here

33
  • Thanks for your help; this is working great with pdftex. However, when switching to LuaLaTeX, I've run into an error: error: (file ./Figures/unset.pdf) (pdf inclusion): reading image failed. Any suggestions on resolving this? It's essential for me to use LuaLaTeX, as some other parts of my document don't function with pdftex. @samcarter-is-at-topanswers-xyz
    – Mycroft_47
    Commented Jun 7 at 21:25
  • Works fine for me with lualatex as well Commented Jun 7 at 21:32
  • What, in your opinion, could be causing the compilation with LuaLaTeX to fail on my computer? see @samcarter-is-at-topanswers-xyz
    – Mycroft_47
    Commented Jun 7 at 21:39
  • 1
    @Mycroft_47 It was a real life demonstration that tex.stackexchange.com/questions/119210/… is absolutely correct to say one needs to be careful when unsetting the colour :) Sorry for the trouble! Commented Jun 7 at 22:46
  • 1
    @Mycroft_47 For this easy example, my identification technique was "find the part with three numbers". For more complicate images, I would use an pdf editor like inkscape to change the colour into something recognisable (0.314 0.314 0.314 or whatever you like) and then search for these numbers Commented Jun 7 at 23:05

You must log in to answer this question.

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