1

I draw and compile tikz pictures standalone:

\documentclass[tikz]{standalone}
\begin{tikzpicture}
 \draw [<->,thick] 
        (0,5) node (yaxis) [left] {$Y$}
        |- 
        (5,0) node (xaxis) [below] {$X$};
\draw[blue,thick] (0,0) -- (4,4);
\end{tikzpicture}
\end{document}

and then include the pdf in a beamer presentation with the usual white background:

\documentclass{beamer}
\begin{document}
\begin{frame}
\includegraphics{tikz_pic.pdf}
\end{frame}
\end{document}

and it works fine:

enter image description here

But if I change the slide background to black (via \setbeamercolor{normal text}{fg=white, bg=black}) it inverts the tikz picture too:

enter image description here

How can I preserve the colors in the tikz picture while changing the slide color?

Note that the same thing happens if you line-in the tikz code to beamer:

\documentclass{beamer}
\begin{document}
\begin{frame}
    \begin{tikzpicture}
     \draw [<->,thick] 
            (0,5) node (yaxis) [left] {$Y$}
            |- 
            (5,0) node (xaxis) [below] {$X$};
    \draw[blue,thick] (0,0) -- (4,4);
    \end{tikzpicture}
\end{frame}
\end{document}

EDIT

I know you can add [background rectangle/.style={fill=white}, show background rectangle] to the tikz picture call and explicitly color lines black:

\begin{tikzpicture}[background rectangle/.style={fill=white}, show background rectangle]
 \draw [<->,thick,black] 
      (0,5) node (yaxis) [left] {$Y$}
        |- 
        (5,0) node (xaxis) [below] {$X$};
\draw[blue,thick] (0,0) -- (4,4);
\end{tikzpicture}

but this also does not work:

enter image description here

Note that this will work if you directly input the tikz code into the frame, but this is very cumbersome when you have many pictures, as it requires completely re-writing a slide deck.

What is odd is that even when the axes are explicitly drawn black, they inherit the beamer text color (white). Yet if you draw the axes in any other color (e.g. gray), they do not inherit the slide text color.

  • No, the solution provided in that post does not work. – invictus Apr 30 '18 at 17:14
  • @invictus the textcolour solution from tex.stackexchange.com/a/336394/36296 works just fine – user36296 Apr 30 '18 at 17:15
  • @samcarter no, it doesn't. In my MWE there is no change. I don't know why you suggest setting the background to red and the text color to black when the question clearly states the slide background should be black. – invictus Apr 30 '18 at 17:18
  • @Kpym I tried that but it also doesn't work. See my edit to the post. – invictus Apr 30 '18 at 17:19
  • @Kpym Yes, look at the updated screenshot. – invictus Apr 30 '18 at 17:27
3

I transform my comment to an answer.

Your image is transparent. You can fill a rectangle in the background, for example by using backgrounds library and adding the style [background rectangle/.style= {fill=white},show background rectangle].

And your first draw command is using the default color (that usually is black), you can put \draw [black,<->,thick] ....

The image (tikz_pic.tex):

\documentclass[tikz]{standalone}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[background rectangle/.style={fill=white}, show background rectangle]
  \draw [<->,thick,black]
      (0,5) node (yaxis) [left] {$Y$} |- (5,0) node (xaxis) [below] {$X$};
  \draw[blue,thick] (0,0) -- (4,4);
\end{tikzpicture}
\end{document}

The Beamer file is unchanged :

\documentclass{beamer}
\setbeamercolor{normal text}{fg=white, bg=black}
\begin{document}
  \begin{frame}
    \includegraphics{tikz_pic.pdf}
  \end{frame}
\end{document}

enter image description here

1

You could explicitly use black as colour:

\documentclass{beamer}
\usepackage{tikz}
\setbeamercolor{normal text}{fg=white, bg=black}
\begin{document}
\begin{frame}
\textcolor{black}{
    \begin{tikzpicture}
     \draw [<->,thick] 
            (0,5) node (yaxis) [left] {$Y$}
            |- 
            (5,0) node (xaxis) [below] {$X$};
    \draw[blue,thick] (0,0) -- (4,4);
    \end{tikzpicture}
    }
\end{frame}
\end{document}

Of course you won't see the black axis on a black background, but you wanted them black ....

enter image description here

  • This doesn't work if you set the background to black! I don't know why you set it to red. – invictus Apr 30 '18 at 17:17
  • @invictus I set it red to still have your black axis visible. – user36296 Apr 30 '18 at 19:06
  • Ok but that ignores away the problem – invictus Apr 30 '18 at 19:10

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