Changing the Text Color in a Shadowed Title

colorshadingshadowstext-decorationstikz-pgf

I am trying to add some shading to a title by modifying code presented in Drop shadow for text in PGF/Beamer

Consider the MWE

\documentclass{article}
\usepackage{tikz}
\usepackage{xcolor}

\newcommand\titleshading[3]{
    \newcommand\xoffset{0.3}
    \newcommand\yoffset{-0.25}
    % Blur
    \foreach \x in {-0.1,0.1} {
        \foreach \y in {-0.1,0.1} {         
            \node[blue!65!white] at (#1em+\xoffset em+\x em,#2em+\yoffset em+\y em) {
                \scalebox{2}{\Huge\texttt{#3}} 
            };
        }
    }

    % Main Shadow
    \node[blue!40!white] at (#1em+0.3em,#2em-0.2em) {
        \scalebox{2}{\Huge\texttt{#3}} 
    };
    \node at (#1em,#2em) {
        \scalebox{2}{\Huge\texttt{#3}} 
    };
}

\begin{document}
\begin{tikzpicture}[remember picture,overlay]   
    \titleshading{8}{0}{Book Title}
  % \titleshading{8}{0}{\textcolor{red}{Book Title}}
\end{tikzpicture} 
\end{document}

which produces the output

enter image description here

Furthermore, I would like to change the color of the black text in the title to say, red.

However, when I replace \titleshading{8}{0}{Book Title} by \titleshading{8}{0}{\textcolor{red}{Book Title}}, everything becomes red:

enter image description here

QUESTION: How may I specify color of the text in the title to be red, while maintaining the light blue shading? Also, if anyone knows of a simpler way to produce this title, I would appreciate being made aware of it.

Thank you.

Best Answer

The third parameter of the macro \titleshading is used for both the main text and the shading; if you color the text there, you'll change it everywhere.

Change only the color of the main text in the macro:

\documentclass{article}
\usepackage{tikz}
\usepackage{xcolor}

\newcommand\titleshading[3]{
    \newcommand\xoffset{0.3}
    \newcommand\yoffset{-0.25}
    % Blur
    \foreach \x in {-0.1,0.1} {
        \foreach \y in {-0.1,0.1} {         
            \node[blue!65!white] at (#1em+\xoffset em+\x em,#2em+\yoffset em+\y em) {
                \scalebox{2}{\Huge\texttt{#3}} 
            };
        }
    }

    % Main Shadow
    \node[blue!40!white] at (#1em+0.3em,#2em-0.2em) {
        \scalebox{2}{\Huge\texttt{#3}} 
    };
    \node[red] at (#1em,#2em) {% <-- here put the color you like 
        \scalebox{2}{\Huge\texttt{#3}} 
    };
}

\begin{document}
\begin{tikzpicture}[remember picture,overlay]   
    \titleshading{8}{0}{Book Title}
\end{tikzpicture} 
\end{document}

enter image description here

A simpler way to do a similar thing may be using the package shadowtext, you do not need to load TikZ here:

\documentclass{article}
\usepackage{xcolor}
\usepackage{graphicx}

\usepackage{shadowtext}
\shadowoffset{2.5pt}
\shadowcolor{blue!65!white}

\newcommand\titleshading[1]{\shadowtext{\color{red}\Huge\ttfamily\scalebox{2}{#1}}}

\begin{document}
\titleshading{Book Title}
\end{document}

enter image description here