2

I guess my question is rather simple, but I am a beginner to latex. So I would appreciate to get some feedback ragarding the following:

I load the following packages in my document:

\documentclass[12pt,a4paper]{scrreprt}
\usepackage[ngerman,english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{helvet}

%tikz \usepackage{tikz} %Due to this line my text color changes

\usepackage[absolute]{textpos}

%math \usepackage{amsmath} \usepackage{amssymb} %graphics \usepackage{graphicx} %for inkscape \usepackage{color} \usepackage{transparent}

\textblockorigin{0mm}{0mm} \renewcommand{\familydefault}{\sfdefault} \definecolor{bblue}{RGB}{0,73,116}

\begin{document}

\begin{titlepage}

\begin{textblock*}{50mm}[0,1](50mm,50mm)
  \color{bblue}\bfseries\Large
  dummy title page in bblue
\end{textblock*}



    \begin{center}
        \color{black}

    \end{center}




\begin{textblock*}{60mm}[0,1](55mm,310mm)
  dummy text as well
\end{textblock*}

\end{titlepage}

\newpage

...Some text...

\end{document}

I added the tikz package last which changed my text color to blue. Before I loaded the package, the color was black which it is also supposed to be. I read that tikz loads a color package internally. Can I may pass some options to the package to avoid that my text color in my document changes?

Thanks!

Sebastiano
  • 54,118
Simon
  • 281
  • 1
    No blue text for me... Could you add \listfiles at the very top of your document, run it through LaTeX, then show the log file, please? – Phelype Oleinik Jul 14 '21 at 11:53
  • I am sorry, I included the title page in my document as well in which a \definecolor command is involved, I updated my question with these two commands. I guess these two lines cause the problem, because this is also the blue which I see later in my whole text. But anyway before I loaded tikz, evrything worked fine and my text was black. Can you help me fixing this? – Simon Jul 14 '21 at 12:57
  • If I run your example, the text still shows back as it should. Unless you can make an example that shows the wrong behaviour, it will be hard to find out how to fix it – Phelype Oleinik Jul 14 '21 at 13:02
  • I provided now a example which works. So if you run the code now the text on the second page is blue, commenting out \usepackge{tikz} makes the text black again. I could fix this now by simple writing \color{black} after the titlepage. But as I said, I would not have to da that without using tikz. Do you know why? – Simon Jul 14 '21 at 13:19

2 Answers2

7

The textblock environment from is not colour safe (a bug). Your example can be simplified to:

\documentclass{article}
\usepackage{xcolor}
\usepackage[absolute]{textpos}
\begin{document}
\begin{textblock*}{50mm}[0,1](50mm,50mm)
  \color{red} dummy title page in bblue
\end{textblock*}
...Some text...
\end{document}

which boils down to the same problem as here.

To work around this issue, while textpos is not fixed, you can add this patch to your document, after textpos is loaded:

% \usepackage[absolute]{textpos}
% The patch must be after textpos is loaded
\usepackage{etoolbox}
\makeatletter
\patchcmd\TP@textblock
  {\TP@textbox=\vbox\bgroup}
  {\TP@textbox=\vbox\bgroup\color@begingroup}
  {}{\PatchFailed}
\patchcmd\TP@commonendtextblock
  {\fi\egroup}
  {\fi\color@endgroup
      \egroup}
  {}{\PatchFailed}

Here's a compilable example:

\documentclass{article}
\usepackage{xcolor}

\usepackage[absolute]{textpos} \usepackage{etoolbox} \makeatletter \patchcmd\TP@textblock {\TP@textbox=\vbox\bgroup} {\TP@textbox=\vbox\bgroup\color@begingroup} {}{\PatchFailed} \patchcmd\TP@commonendtextblock {\fi\egroup} {\fi\color@endgroup \egroup} {}{\PatchFailed}

\begin{document}

\begin{textblock}{50mm}0,1 \color{red} dummy title page in bblue \end{textblock}

...Some text...

\end{document}

enter image description here

4

Ok, so, this issue occurs because tikz loads xcolor instead of color (the latter of which should have stayed in the 80's were it belongs). It also loads graphicx, so unless you want to pass options to either of them, you don't need to load them again. By explicitly loading xcolor instead of color you can actually reproduce the behaviour of your code aswell.

To solve your problem with the text, there are several options:

  1. Put the text you want blue in curly braces like so:

    {\color{bblue}\bfseries\Large dummy title page in bblue}

  2. Use the \textcolor{}{} command like so:

    \textcolor{bblue}{\bfseries\Large dummy title page in bblue}

Markus G.
  • 2,735
  • Thanks! What you say makes sense to me, but as I said, if I don't load the tikz package everything works fine. So what is explicitely the problem after loading tikz? – Simon Jul 15 '21 at 07:05
  • The difference is that by loading tikz you are in effect (also) loading xcolor. Apparently, xcolor overrides how the color package implements \color{}. Don't ask me for details, which are beyond my understanding of how these packages work. I'd refer you the @Phelype's answer who pointed out that textblock is not colorsafe, i.e. even though you have an \end{} the \color{} definition is not restricted. – Markus G. Jul 15 '21 at 12:50