4

I like the simple implementation for QR codes in Latex, for example:

\usepackage{qrcode}

...

\qrcode[height=1in]{https://www.ctan.org/tex-archive/macros/latex/contrib/qrcode?lang=en}

But... is it possible to change the color?

Schweinebacke
  • 26,336

2 Answers2

10

Like for other elements in LaTeX:

\documentclass{article}

%\usepackage{xcolor}
\usepackage{qrcode}

\begin{document}
\textcolor{blue}{\qrcode[height=1in]{https://www.ctan.org/tex-archive/macros/latex/contrib/qrcode?lang=en}}
\end{document}

You even don't need to load xcolor, because qrcode already loads xcolor (without using it). But you can load it before qrcode, if you want to add options:

\documentclass{article}

\usepackage[svgnames]{xcolor}
\usepackage{qrcode}

\begin{document}
\textcolor{DarkBlue}{\qrcode[height=1in]{https://www.ctan.org/tex-archive/macros/latex/contrib/qrcode?lang=en}}
\textcolor{Blue}{\qrcode[height=1in]{https://www.ctan.org/tex-archive/macros/latex/contrib/qrcode?lang=en}}
\textcolor{LightBlue}{\qrcode[height=1in]{https://www.ctan.org/tex-archive/macros/latex/contrib/qrcode?lang=en}}

\end{document}

qrcode with different colors

Note: The contrast of QR-Codes should be high. So the last one at the example above shouldn't be used!

This does work for all colors, e.g., a self defined:

\documentclass{article}

\usepackage{qrcode}
\definecolor{myblue}{cmyk}{1.0,0.8,0.05,0.20}

\begin{document}
\textcolor{myblue}{\qrcode[height=1in]{https://www.ctan.org/tex-archive/macros/latex/contrib/qrcode?lang=en}}

\end{document}

with self defined color

Schweinebacke
  • 26,336
  • unfortunately this doesn't seem to work for self-defined colors \definecolor{myblue}{cmyk}{1.0,0.8,0.05,0.20} – Joost Döbken Oct 13 '17 at 10:03
  • 1
    @API: Surely it does! – Schweinebacke Oct 13 '17 at 10:05
  • 6
    When using hyperref in conjuction with colorlinks=true and e.g. urlcolor=[named]{blue}, the \textcolor{COLOR}{\qrcode{SOMETHING}} command seems to ignore the COLOR. – norok2 Jun 12 '18 at 10:31
  • Unfortunately as pointed out by @norok2, this is not working in combination with hyperref. – lumbric Mar 06 '20 at 15:08
  • 1
    @norok2 @lumbric hyperref was not mentioned in the question. If you load package hyperref and the qrcodes should not be links, add package option nolinks: \usepackage[nolinks]{qrcode}. You can also use option nolink for \qrcode: \qrcode[nolink]{SOMETHING} or the starred version \qrcode*: \qrcode*{SOMETHING}. – esdd Mar 07 '20 at 17:18
  • 3
    @norok2 @lumbric If the qrcode should be a link using the color given by \textcolor: \textcolor{COLOR}{\hypersetup{urlcolor=.}\qrcode{SOMETHING}}. But then to have to ensure that \hypersetup is defined. – esdd Mar 07 '20 at 17:22
0

For me the following Setup worked:

\usepackage[dvipsnames]{xcolor}

\usepackage[breaklinks=true]{hyperref} \hypersetup{ colorlinks = true, linkcolor = NavyBlue, urlcolor = NavyBlue, citecolor = NavyBlue, filecolor = NavyBlue, }

\usepackage{qrcode}

Apparently, filecolor was the one changing the color of the QR code itself. I prefer NavyBlue, but you could choose any color you like. In this case, using \textcolor does not work and is overwritten by the color options defined on \hypersetup.