4

I am inserting an image from Inkscape using the pdf + LaTeX option since I want the text to appear in the same font and size as in the rest of my document.

Can I change the color of the text?

\documentclass{article}
\usepackage{graphicx}
\usepackage{color}

\begin{document} 
Some text before the figure.

\color{red}

\begin{figure}
 \centering
 \def\svgwidth{\textwidth}
 \input{figure.pdf_tex}
 \caption{Example Figure}
\end{figure}

Some text after the figure.
\end{document}

The following is the content of the figure.pdf_tex file:

\begingroup%
  \makeatletter%
  \providecommand\color[2][]{%
    \errmessage{(Inkscape) Color is used for the text in Inkscape, but the package 'color.sty' is not loaded}%
    \renewcommand\color[2][]{}%
  }%
  \providecommand\transparent[1]{%
    \errmessage{(Inkscape) Transparency is used (non-zero) for the text in Inkscape, but the package 'transparent.sty' is not loaded}%
    \renewcommand\transparent[1]{}%
  }%
  \providecommand\rotatebox[2]{#2}%
  \ifx\svgwidth\undefined%
    \setlength{\unitlength}{782.075bp}%
    \ifx\svgscale\undefined%
      \relax%
    \else%
      \setlength{\unitlength}{\unitlength * \real{\svgscale}}%
    \fi%
  \else%
    \setlength{\unitlength}{\svgwidth}%
  \fi%
  \global\let\svgwidth\undefined%
  \global\let\svgscale\undefined%
  \makeatother%
  \begin{picture}(1,0.48489595)%
    \put(0,0){\includegraphics[width=\unitlength]{figure.pdf}}%
    \put(0.21413974,0.24055332){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{Text}}}%
  \end{picture}%
\endgroup%

The example figure as jpg

6
  • 1
    doesn't \color{red} work? If not please post a small example Feb 18, 2014 at 14:02
  • If the text is already in the image, no. Feb 18, 2014 at 14:27
  • @JohnKormylo well no of course but the pdf+latex option writes the image as an image with the text as a tex fragment to overlay the image. Feb 18, 2014 at 14:31
  • 1
    Huh. Can one then separate and edit the tex fragment? Feb 18, 2014 at 14:38
  • @DavidCarlisle: That only changes the text color of the text that comes after the figure.
    – Bettina
    Feb 18, 2014 at 14:52

1 Answer 1

6

The figure envirnoment always resets the color to the document default, normally black so you need the \color command inside the environment.

\begin{figure}\color{red}

That will make any text in the environment including the caption go red.

Then inkscape has hardwired the colors of the text

 \put(0.21413974,0.24055332){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{Text}}}%

so if you want it to pick up the current color you need to remove the

\color[rgb]{0,0,0}

or alternatively redefine the command to do nothing after you have set your color so

 \begin{figure}\color{red}\renewcommand\color[2][]{}

will set red then disable any other \color commands in the figure so you don't need to edit the generated file.

3
  • Can I change the color that inkscape hardwires into the pdf_tex file? (This is not really a LaTeX question, but would also solve my problem)
    – Bettina
    Feb 18, 2014 at 15:16
  • Including ´\color{red}\renewcommand\color[2][]{}´in the figure solves my problem. Now, when I include the caption package it will even leave my caption black.
    – Bettina
    Feb 18, 2014 at 15:40
  • @Bettina possibly, I've never used inkscape though, so don't ask me:-) Feb 18, 2014 at 15:51

You must log in to answer this question.

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