2

I would like to be able to overlay a title of one color onto the same title of a different color to achieve a different effect; and I would like, if possible, to do this automatically without creating a special environment. (This is easy to do with, say, apspicture with two\rput commands)

Consider

\documentclass{book}
\usepackage{xcolor}
\definecolor{aqua}{RGB}{0, 188, 188}

\begin{document}
\thispagestyle{empty}
\Huge

\begin{center}
\textbf{\color{black}{HOW TO OVERLAY THIS TITLE}}

\textbf{\color{aqua}{HOW TO OVERLAY THIS TITLE}}

\vspace*{45pt}

{\textbf{\color{black}{HOW TO OVERLAY THIS TITLE}}}\\[-30pt]

{\textbf{\color{aqua}{HOW TO OVERLAY THIS TITLE}}}
\end{center}

\vspace*{35pt}

That is, how to do it \underline{\textit{automatically}}.
\end{document}   

which yields

enter image description here

In the MWE, I want to overlay the light aqua title over the black title---which I had accomplished by "trial and error" and inspection using a series of \\[] commands until I determined that \\[-30pt] seems to work.

But, I would like to know if there is a command of some sort that will do this automatically without invoking any special environment like pspicture, tikz, etc.? (Or is, perhaps, trial and error with negative vertical skips the (only) way for the usual document environment?)

5
  • \rlap and \llap can be used to overlay things, and \raisebox cam be used to change the baseline. Just how "automatic" do you want it? (It's supposed to be automatic, but you actually have to push this button.) Commented May 30, 2022 at 19:28
  • @JohnKormylo I'm not sure what you mean by \rlap and \llap; but by automatic, I mean using code to do the overlaying, as opposed to the trial and error method of negative vertical skips until the overlay is approximated by vision.
    – DDS
    Commented May 30, 2022 at 19:38
  • @jean-marie are you sure, that what you do here is what you really want? The reason I am asking is, that theoretically speaking, you place the exact same size of text on itself and hence it will be totally covered. The halo you see is just a technical artifact created by the PDF reader of your choice. So it is more an error and even when you consider it your desired result, it looks like Word97 WordArt. Nevertheless I provided two technical solutions in an answer.
    – TobiBS
    Commented May 30, 2022 at 20:04
  • @TobiBS Perhaps it is an optical illusion (I didn't think of that), but it seems: (1) I can adjust the shade of the lighter "top" title by placing it atop a darker lower title---and the net result, at least to me, visually, is nicer aesthetically, than using some kind of fake bold.
    – DDS
    Commented May 30, 2022 at 20:23
  • @jean-marie OK, if it is your flavor, enjoy the solution. But be aware that depending of the device and viewer, results might differ.
    – TobiBS
    Commented May 30, 2022 at 20:28

3 Answers 3

4

This will work if the two versions are the exact same size. Otherwise you would have to overlay each letter separately.

\documentclass{article}
\usepackage{xcolor}
\definecolor{aqua}{RGB}{0, 188, 188}

\newcommand{\mytitle}[1]% #1 = title
{\bgroup
  \Huge
  \sbox0{\parbox{\columnwidth}{\centering\textbf{\color{black}#1}}}%
  \sbox1{\parbox{\columnwidth}{\centering\textbf{\color{aqua}#1}}}%
  \noindent\usebox0\llap{\raisebox{1pt}{\usebox1}}
\egroup}

\begin{document}
\mytitle{HOW TO OVERLAY THIS TITLE}
\end{document}

demo

3
  • Why do you raise the box by 1pt? The OP asked for the exact overlap over the first.
    – TobiBS
    Commented May 30, 2022 at 20:27
  • So you can see both versions. Besides, this is how shadow lettering is done. Commented May 30, 2022 at 20:57
  • Thank you for this very helpful answer.
    – DDS
    Commented May 30, 2022 at 22:58
2

An easy way to do this is by letting LaTeX calculate the width of the box just written and then jump back horizontally, as shown here:

\documentclass{book}
\usepackage{xcolor}
\definecolor{aqua}{RGB}{0, 188, 188}

\newlength{\aqualength}
\newcommand{\aqualay}[1]{%
\bfseries%
\settowidth{\aqualength}{#1}%
\color{black}{#1}%
\hspace{-\aqualength}%
\color{aqua}{#1}%
}

\begin{document}
    \thispagestyle{empty}
    \Large
    \begin{center}      
        \aqualay{HOW TO OVERLAY THIS TITLE}
    \end{center}
\end{document}

The result is: enter image description here


Using your vertical approach one would be able to use the negative \baselineskip:

\documentclass{book}
\usepackage{xcolor}
\definecolor{aqua}{RGB}{0, 188, 188}

\begin{document}
    \thispagestyle{empty}
    \Large
    
    \begin{center}
        \textbf{\color{black}{HOW TO OVERLAY THIS TITLE}}
        
        \textbf{\color{aqua}{HOW TO OVERLAY THIS TITLE}}
        
        \vspace*{45pt}
        
        {\textbf{\color{black}{HOW TO OVERLAY THIS TITLE}}}\\[-\baselineskip]
        
        {\textbf{\color{aqua}{HOW TO OVERLAY THIS TITLE}}}
    \end{center}
    
    \vspace*{35pt}
    
    That is, how to do it \underline{\textit{automatically}}.
\end{document}   
2
  • As an extension of my previous comment---thank you for taking the time to post these answers. (+1)
    – DDS
    Commented May 30, 2022 at 20:24
  • @jean-marie you are welcome, just decide which solution suits you best. One thing where the solution of John is superior is the multiline compatibility. My solution will only work for one line titles.
    – TobiBS
    Commented May 30, 2022 at 20:29
1

Another variant using the package xcoffins that allows the precise joining of boxes without guessing.

The command \OverlayTitle{color upper}{color back}{text}{x offset}{y offset} will typeset the overlay.

a

\documentclass{book}
\textwidth=6.5in
\usepackage{xcolor}
\definecolor{aqua}{RGB}{0, 188, 188}

\usepackage{xcoffins}
\NewCoffin\upperlayer
\NewCoffin\lowerlayer
\NewCoffin\framex
\newcommand{\OverlayTitle}[5]{% 
\SetHorizontalCoffin\upperlayer{\color{#1}#3}
\SetHorizontalCoffin\lowerlayer{\color{#2}#3}
\SetHorizontalCoffin\framex{}
\JoinCoffins*\framex[l,t]\lowerlayer[l,t]   
\JoinCoffins*\framex[l,t]\upperlayer[l,t](#4,#5)
\TypesetCoffin\framex   
}

\begin{document}
    \thispagestyle{empty}
    \Huge
    
    \OverlayTitle{aqua}{black}{HOW TO OVERLAY THIS TITLE}{-0.5pt}{0.5pt}    
    
    \bigskip
    
    \OverlayTitle{red}{black}{HOW TO OVERLAY THIS TITLE}{1pt}{1pt}  
    
\end{document}   

You must log in to answer this question.

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