# Typeset two styles of the same text over top each other

So the goal of this exercise is to have text that can be displayed via the ocg-p package in two distinct styles depending on the OCG layer that is in effect (similar to this question/answer). The heart of this question is in typesetting two versions of the same text on top of each other; OCG is not where my problem lies.

## Question:

I have two styles that I need to layer. How can I actually typeset the same content in the same location on the page in two different styles? That is, I get how to typeset things on a small scale in the same space, perhaps with something like:

After this, \rlap{This is one version}This is another version

This is completely separate.


But... How do I go about doing that for something that is a multi-line, full page environment?

Note, my other question refers specifically to this problem from the perspective of getting ocg-p to work for the solution. This question is about making the content typeset twice, in two styles, over top each other.

To get the desired effect, I need to have one OCG-wrapped environment with a monochrome style in the same location on the page as a color style. I'd like to do this in two locations:

1. Title page (full page)
2. Section/Chapter titles

The color style should be presented as the base layer, while the black and white should be layered on top via OCG on top of the color style. OCG will be used to present the black and white layer so that it does not display by default, but always prints (as shown below). This will allow for graceful degradation, with the B&W version both showing on screen and printing in PDF viewers that do not have OCG compatibility (virtually anything besides Adobe...).

\begin{ocg}[printocg=always]{MonochromeVersion}{monochrome}{0}
content ...
\end{ocg}


## MWE

This code presents the two styles that I'd like to layer as static versions that are distinguished by the state of the bool named usecolor. This variable is set up front, and the document is typeset in the set style:

\setbool{usecolor}{false}


The full example:

\documentclass[titlepage,twoside,11pt]{article}

\usepackage[demo]{graphicx}

\usepackage{etoolbox}
\providebool{usecolor}
% Will set color title page and section headings
\setbool{usecolor}{false}

% ----- STY File Contents
% Set page geometry

%%%% Title Page stuff
\ifbool{usecolor}{%
\usepackage[pagecolor=none]{pagecolor}%
\definecolor{MyBlue}{HTML}{1b3667}%
\usepackage{afterpage}}{}

\newcommand{\MyTitle}[2]
{
\thispagestyle{empty}
\ifbool{usecolor}{%
\pagecolor{MyBlue}%
\afterpage{\nopagecolor}}{}
\begin{center}
{\ifbool{usecolor}{\color{white}\sffamily}{\sffamily}%  Set text color white or leave black
% put logo gold or blue
\ifbool{usecolor}{\includegraphics[width=1.5in]{logo-gold}}{\includegraphics[width=1.5in]{logo-white}}
\\\vskip 1in
\begin{huge}
\textbf{#1}
\vskip 0.1ex\rule{0.5\textwidth}{0.8pt}\vskip 1ex
#2\\
\end{huge}
\vfill
\large Authors:  \ldots \\
\vfill
}
\end{center}
\newpage
}

%%%% Section Style Format
\usepackage[usenames,svgnames]{xcolor}
\usepackage{tikz}
\usepackage{mathabx}
\usepackage[explicit]{titlesec}
\newcommand*\sectionlabel{}
\titleformat{\section}
{\gdef\sectionlabel{}
\thispagestyle{plain}\ifbool{usecolor}{\color{white}}{}\normalfont\sffamily\LARGE}
{\gdef\sectionlabel{\thesection.\ \ }}{0pt}
{\begin{tikzpicture}[remember picture,overlay]
\node[xshift=-.2in,rounded corners=.5cm,inner sep=11pt] at (0,0)
{\begin{tikzpicture}[remember picture, overlay]
\ifbool{usecolor}{\fill[MyBlue]}{\draw[fill=LightGrey]} (0,0) rectangle
(\paperwidth,1cm);
\node[anchor=west,xshift=.1in,yshift=.5cm,rectangle]
{\sectionlabel#1};
\end{tikzpicture}
};
\end{tikzpicture}
}
\titlespacing*{\section}{0pt}{50pt}{10pt}

\begin{document}
\MyTitle{Title}{Subtitle}

\section{First Section Title}

\end{document}

• This is a possible duplicate of this question. If one is closed, I suggest that this one is kept. Apr 3 '14 at 22:48
• Is this a question? That is, it is all explained very nicely and I'm fairly clear what the question isn't. But as to what the question might be, assuming there is one... I don't know anything about OCG but that is apparently not the problem. Neither is generating the styles to be layered using OCG. So what's left? By the way, I personally think the other question is clearer. That is, it is a question. I don't really understand why the additional information here wasn't added to the original question. Am I missing something?
– cfr
Apr 3 '14 at 22:51
• @nickie, The question you refer to is aimed at the the layering aspect from the perspective of OCG and getting one layer to display and another to print. I'm starting to wrap my head around how to do this with ocg-p, and I will present a self-answer as it becomes clear. This question represents the part that I am stuck on, that is actually developing the two layers to pass through to ocg-p such that they are typeset in the same area of the page. Apr 4 '14 at 0:36
• @cfr, I have edited to hopefully make this clearer. As I mentioned in my other comment, the main issue for me now is to present the styles over top of each other, in the same area of the page. This isn't really a natural thing for LaTeX to do, as far as I can tell. Apr 4 '14 at 0:39
• Can you use tikz to just put one in the background layer? At least for the title page (not sure how well it would work for sections).
– cfr
Apr 4 '14 at 0:42

This shamelessly pinches the solution cslstr posted for the sections and applies it to the title page as well. Note that I was quite careful in rewriting \MyTitle to get the formatting correct but that there are very slight changes to the spacing of elements of the title page. If this is a problem, further adjustments are obviously possible but this looked 'close enough' to me for almost all practical purposes.

Caveat: I have no idea how this should display in a pdf viewer. In acroread, I can switch to the monochrome layer and get monochrome for both title page and section heading. In Okular, the monochrome does not appear to be available for either title page or section heading. I'm therefore assuming this is what it should be like since you said the section heading solution worked and my title page code seems to behave in the same way. But I'd never even heard of OCG until you posted this question...

Further caveat: my tikz skills are only slightly less limited than my knowledge of OCG...

Caveat emptor!

\documentclass[titlepage,twoside,11pt]{article}

\usepackage[demo]{graphicx}
\usepackage[usenames,svgnames]{xcolor}
\usepackage{tikz}
\usepackage{mathabx}
\usepackage[explicit]{titlesec}
\usepackage{ocg-p}
\usepackage{etoolbox}
\providebool{usecolor}
% Will set color title page and section headings
\setbool{usecolor}{false}

% ----- STY File Contents
% Set page geometry

%%%% Title Page stuff
% \ifbool{usecolor}{%
\usepackage[pagecolor=none]{pagecolor}%
\definecolor{MyBlue}{HTML}{1b3667}%
\usepackage{afterpage}%}{}

\newcommand{\MyTitle}[2]
{\thispagestyle{empty}%
\noindent
\begin{tikzpicture}[overlay, remember picture, text=white]
\fill [fill=MyBlue] (current page.south west) rectangle (\paperwidth,\paperheight);
\node at (.5\linewidth,-2.125) {\includegraphics[width=1.5in]{logo-gold}};
\node [font={\huge\bfseries\sffamily}] at (.5\linewidth,-7) {#1};
\node [font={\huge\sffamily}] at (.5\linewidth,-9.125) {#2};
\node [font={\large\sffamily}] at (.5\linewidth,-15.5) {Authors\dots};
\node (p) at (.25\linewidth,-8.25) {};
\node (q) at (.75\linewidth,-8.25) {};
\draw [color=white] (p) -- (q);
\end{tikzpicture}
\begin{ocg}[printocg=always]{MonochromeVersion}{monochrome}{0}
\begin{tikzpicture}[overlay, remember picture, text=black]
\fill [fill=white] (current page.south west) rectangle (\paperwidth,\paperheight);
\node at (.5\linewidth,-2.125) {\includegraphics[width=1.5in]{logo-white}};
\node [font={\huge\bfseries\sffamily}] at (.5\linewidth,-7) {#1};
\node [font={\huge\sffamily}] at (.5\linewidth,-9.125) {#2};
\node [font={\large\sffamily}] at (.5\linewidth,-15.5) {Authors\dots};
\node (p) at (.25\linewidth,-8.25) {};
\node (q) at (.75\linewidth,-8.25) {};
\draw (p) -- (q);
\end{tikzpicture}
\end{ocg}
\afterpage{\nopagecolor}%
\newpage
}

%%%% Section Style Format
\usepackage{tikz}
\usepackage{mathabx}
\usepackage[explicit]{titlesec}
\newcommand*\sectionlabel{}
\titleformat{\section}
{\gdef\sectionlabel{}
\thispagestyle{plain}\ifbool{usecolor}{}{}\normalfont\sffamily\LARGE}
{\gdef\sectionlabel{\thesection.\ \ }}{0pt}
{\begin{tikzpicture}[remember picture,overlay]
\node[xshift=-.2in,rounded corners=.5cm,inner sep=11pt] at (0,0)
{\begin{tikzpicture}[remember picture, overlay]\color{white}
\fill[MyBlue] (0,0) rectangle
(\paperwidth,1cm);
\node[anchor=west,xshift=.1in,yshift=.5cm,rectangle]
{\sectionlabel#1};
\end{tikzpicture}
};
\end{tikzpicture}%
\begin{ocg}[printocg=always]{MonochromeVersion}{monochrome}{0}
\begin{tikzpicture}[remember picture,overlay]
\node[xshift=-.2in,yshift=-0.02cm,rounded corners=.52cm,inner sep=11pt] at (0,0)
{\begin{tikzpicture}[remember picture, overlay]\color{black}
\fill[LightGrey] (0,0) rectangle
(\paperwidth,1.04cm);
\node[anchor=west,xshift=.1in,yshift=.5cm,rectangle]
{\sectionlabel#1};
\end{tikzpicture}
};
\end{tikzpicture}
\end{ocg}
}
\titlespacing*{\section}{0pt}{50pt}{10pt}

\begin{document}
\MyTitle{Title}{Subtitle}

\section{First Section Title}

\end{document}


Note: you should really tell geometry about headheight. There's no point in using the package if you then undermine its efforts by sneaking changes behind its back!

acroread standard layer:

acroread monochrome layer:

Okular:

# EDIT

If you wish to accommodate multi-line titles but are prepared to specify the line breaks manually, you can do this:

\documentclass[titlepage,twoside,11pt]{article}

\usepackage[demo]{graphicx}
\usepackage[usenames,svgnames]{xcolor}
\usepackage{tikz}
\usepackage{mathabx}
\usepackage[explicit]{titlesec}
\usepackage{ocg-p}
\usepackage{etoolbox}
\providebool{usecolor}
% Will set color title page and section headings
\setbool{usecolor}{false}

% ----- STY File Contents
% Set page geometry

%%%% Title Page stuff
% \ifbool{usecolor}{%
\usepackage[pagecolor=none]{pagecolor}%
\definecolor{MyBlue}{HTML}{1b3667}%
\usepackage{afterpage}%}{}

\newcommand{\MyTitle}[2]
{\thispagestyle{empty}%
\noindent
\begin{tikzpicture}[overlay, remember picture, text=white, align=center]
\fill [fill=MyBlue] (current page.south west) rectangle (\paperwidth,\paperheight);
\node at (.5\linewidth,-2.125) {\includegraphics[width=1.5in]{logo-gold}};
\node [font={\huge\bfseries\sffamily}] at (.5\linewidth,-7) {#1};
\node [font={\huge\sffamily}] at (.5\linewidth,-9.125) {#2};
\node [font={\large\sffamily}] at (.5\linewidth,-15.5) {Authors\dots};
\node (p) at (.25\linewidth,-8.25) {};
\node (q) at (.75\linewidth,-8.25) {};
\draw [color=white] (p) -- (q);
\end{tikzpicture}
\begin{ocg}[printocg=always]{MonochromeVersion}{monochrome}{0}
\begin{tikzpicture}[overlay, remember picture, text=black, align=center]
\fill [fill=white] (current page.south west) rectangle (\paperwidth,\paperheight);
\node at (.5\linewidth,-2.125) {\includegraphics[width=1.5in]{logo-white}};
\node [font={\huge\bfseries\sffamily}] at (.5\linewidth,-7) {#1};
\node [font={\huge\sffamily}] at (.5\linewidth,-9.125) {#2};
\node [font={\large\sffamily}] at (.5\linewidth,-15.5) {Authors\dots};
\node (p) at (.25\linewidth,-8.25) {};
\node (q) at (.75\linewidth,-8.25) {};
\draw (p) -- (q);
\end{tikzpicture}
\end{ocg}
\afterpage{\nopagecolor}%
\newpage
}

%%%% Section Style Format
\usepackage{tikz}
\usepackage{mathabx}
\usepackage[explicit]{titlesec}
\newcommand*\sectionlabel{}
\titleformat{\section}
{\gdef\sectionlabel{}
\thispagestyle{plain}\ifbool{usecolor}{}{}\normalfont\sffamily\LARGE}
{\gdef\sectionlabel{\thesection.\ \ }}{0pt}
{\begin{tikzpicture}[remember picture,overlay]
\node[xshift=-.2in,rounded corners=.5cm,inner sep=11pt] at (0,0)
{\begin{tikzpicture}[remember picture, overlay]\color{white}
\fill[MyBlue] (0,0) rectangle
(\paperwidth,1cm);
\node[anchor=west,xshift=.1in,yshift=.5cm,rectangle]
{\sectionlabel#1};
\end{tikzpicture}
};
\end{tikzpicture}%
\begin{ocg}[printocg=always]{MonochromeVersion}{monochrome}{0}
\begin{tikzpicture}[remember picture,overlay]
\node[xshift=-.2in,yshift=-0.02cm,rounded corners=.52cm,inner sep=11pt] at (0,0)
{\begin{tikzpicture}[remember picture, overlay]\color{black}
\fill[LightGrey] (0,0) rectangle
(\paperwidth,1.04cm);
\node[anchor=west,xshift=.1in,yshift=.5cm,rectangle]
{\sectionlabel#1};
\end{tikzpicture}
};
\end{tikzpicture}
\end{ocg}
}
\titlespacing*{\section}{0pt}{50pt}{10pt}

\begin{document}
\MyTitle{This is an Extremely Long Title\\of the Multi-Line Kind and Should Be Broken}{Subtitle}

\section{First Section Title}

\end{document}


If you would prefer to keep the distance between the title and the line, rather than keeping the location of the line constant, you could try:

\documentclass[titlepage,twoside,11pt]{article}

\usepackage[demo]{graphicx}
\usepackage[usenames,svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{mathabx}
\usepackage[explicit]{titlesec}
\usepackage{ocg-p}
\usepackage{etoolbox}
\providebool{usecolor}
% Will set color title page and section headings
\setbool{usecolor}{false}

% ----- STY File Contents
% Set page geometry

%%%% Title Page stuff
% \ifbool{usecolor}{%
\usepackage[pagecolor=none]{pagecolor}%
\definecolor{MyBlue}{HTML}{1b3667}%
\usepackage{afterpage}%}{}

\newcommand{\MyTitle}[2]
{\thispagestyle{empty}%
\noindent
\begin{tikzpicture}[overlay, remember picture, text=white, align=center]
\fill [fill=MyBlue] (current page.south west) rectangle (\paperwidth,\paperheight);
\node at (.5\linewidth,-2.125) {\includegraphics[width=1.5in]{logo-gold}}
node (title) [font={\huge\bfseries\sffamily}] at (.5\linewidth,-7) {#1}
node [font={\huge\sffamily}, below=2.125 of title.south] {#2}
node [font={\large\sffamily}] at (.5\linewidth,-15.5) {Authors\dots}
node (p) [below left=1.25 and .25\linewidth of title.south] {}
node (q) [below right=1.25 and .25\linewidth of title.south] {};
\draw [color=white] (p) -- (q);
\end{tikzpicture}
\begin{ocg}[printocg=always]{MonochromeVersion}{monochrome}{0}
\begin{tikzpicture}[overlay, remember picture, text=black, align=center]
\fill [fill=white] (current page.south west) rectangle (\paperwidth,\paperheight);
\node at (.5\linewidth,-2.125) {\includegraphics[width=1.5in]{logo-white}}
node (title) [font={\huge\bfseries\sffamily}] at (.5\linewidth,-7) {#1}
node [font={\huge\sffamily}, below=2.125 of title.south] {#2}
node [font={\large\sffamily}] at (.5\linewidth,-15.5) {Authors\dots}
node (p) [below left=1.25 and .25\linewidth of title.south] {}
node (q) [below right=1.25 and .25\linewidth of title.south] {};
\draw (p) -- (q);
\end{tikzpicture}
\end{ocg}
\afterpage{\nopagecolor}%
\newpage
}

%%%% Section Style Format
\usepackage{tikz}
\usepackage{mathabx}
\usepackage[explicit]{titlesec}
\newcommand*\sectionlabel{}
\titleformat{\section}
{\gdef\sectionlabel{}
\thispagestyle{plain}\ifbool{usecolor}{}{}\normalfont\sffamily\LARGE}
{\gdef\sectionlabel{\thesection.\ \ }}{0pt}
{\begin{tikzpicture}[remember picture,overlay]
\node[xshift=-.2in,rounded corners=.5cm,inner sep=11pt] at (0,0)
{\begin{tikzpicture}[remember picture, overlay]\color{white}
\fill[MyBlue] (0,0) rectangle
(\paperwidth,1cm);
\node[anchor=west,xshift=.1in,yshift=.5cm,rectangle]
{\sectionlabel#1};
\end{tikzpicture}
};
\end{tikzpicture}%
\begin{ocg}[printocg=always]{MonochromeVersion}{monochrome}{0}
\begin{tikzpicture}[remember picture,overlay]
\node[xshift=-.2in,yshift=-0.02cm,rounded corners=.52cm,inner sep=11pt] at (0,0)
{\begin{tikzpicture}[remember picture, overlay]\color{black}
\fill[LightGrey] (0,0) rectangle
(\paperwidth,1.04cm);
\node[anchor=west,xshift=.1in,yshift=.5cm,rectangle]
{\sectionlabel#1};
\end{tikzpicture}
};
\end{tikzpicture}
\end{ocg}
}
\titlespacing*{\section}{0pt}{50pt}{10pt}

\begin{document}
\MyTitle{This is an Extremely Long Title\\of the Multi-Line Kind and Should Be Broken}{Subtitle}

\section{First Section Title}

\end{document}


• I notice that you set each "line" in its own tikz node. Is this the only/best way to accomplish this? Is there a way to handle very long (two-liner) titles [both line breaking and subsequent spacing] in a robust way with tikz? Apart from that issue, this appears to do just what I am looking for. Apr 5 '14 at 1:53
• @cslstr Does my edit help? I think you will have to break the line manually but I guess that it common with long titles if you want it to look 'balanced'. Either you can keep the space for the title constant or you can adjust the line and subtitle down. (Or you could adjust it down by a smaller amount if you preferred, of course.) I give examples of both.
– cfr
Apr 5 '14 at 2:52
• The edit is useful - it would be nice if traditional typesetting/spacing were available for real within tikz, but this will do for my purposes. Apr 23 '14 at 4:14

The following MWE works as intended for the 2nd part only - just for the section header design. Created PDF will open in Adobe reader with color heading, but print in B&W/monochrome.

MWE:

\documentclass[titlepage,twoside,11pt]{article}

\usepackage[demo]{graphicx}

\usepackage{etoolbox}
\providebool{usecolor}
% Will set color title page and section headings
\setbool{usecolor}{true}

% ----- STY File Contents
% Set page geometry

\usepackage[usenames,svgnames]{xcolor}
\usepackage{ocg-p}

%%%% Title Page stuff
\ifbool{usecolor}{%
\usepackage[pagecolor=none]{pagecolor}%
\definecolor{MyBlue}{HTML}{1b3667}%
\usepackage{afterpage}}{}

\newcommand{\MyTitle}[2]
{
\thispagestyle{empty}
\ifbool{usecolor}{%
\pagecolor{MyBlue}%
\afterpage{\nopagecolor}}{}
\begin{center}
{\ifbool{usecolor}{\color{white}\sffamily}{\sffamily}%  Set text color white or leave black
% put logo gold or blue
\ifbool{usecolor}{\includegraphics[width=1.5in]{logo-gold}}{\includegraphics[width=1.5in]{logo-white}}
\\\vskip 1in
\begin{huge}
\textbf{#1}
\vskip 0.1ex\rule{0.5\textwidth}{0.8pt}\vskip 1ex
#2\\
\end{huge}
\vfill
\large Authors:  \ldots \\
\vfill
}
\end{center}
\newpage
}

%%%% Section Style Format
\usepackage{tikz}
\usepackage{mathabx}
\usepackage[explicit]{titlesec}
\newcommand*\sectionlabel{}
\titleformat{\section}
{\gdef\sectionlabel{}
\thispagestyle{plain}\ifbool{usecolor}{}{}\normalfont\sffamily\LARGE}
{\gdef\sectionlabel{\thesection.\ \ }}{0pt}
{\begin{tikzpicture}[remember picture,overlay]
\node[xshift=-.2in,rounded corners=.5cm,inner sep=11pt] at (0,0)
{\begin{tikzpicture}[remember picture, overlay]\color{white}
\fill[MyBlue] (0,0) rectangle
(\paperwidth,1cm);
\node[anchor=west,xshift=.1in,yshift=.5cm,rectangle]
{\sectionlabel#1};
\end{tikzpicture}
};
\end{tikzpicture}%
\begin{ocg}[printocg=always]{MonochromeVersion}{monochrome}{0}
\begin{tikzpicture}[remember picture,overlay]
\node[xshift=-.2in,yshift=-0.02cm,rounded corners=.52cm,inner sep=11pt] at (0,0)
{\begin{tikzpicture}[remember picture, overlay]\color{black}
\fill[LightGrey] (0,0) rectangle
(\paperwidth,1.04cm);
\node[anchor=west,xshift=.1in,yshift=.5cm,rectangle]
{\sectionlabel#1};
\end{tikzpicture}
};
\end{tikzpicture}
\end{ocg}
}
\titlespacing*{\section}{0pt}{50pt}{10pt}

\begin{document}
\MyTitle{Title}{Subtitle}

\section{First Section Title}

\end{document}


Here, I am trying to answer the OP's query, "How do I go about doing that [\rlap example] for something that is a multi-line, full page environment?" What I do here is save the two versions in separate \vboxes, and then stack them atop each other. This approach will not break across pages and is currently limited to stuff between the margins, though of course this latter limitation can likely be worked around.

In this MWE, I have two nearly identical compositions, one in red and the other in blue. One is in \upshape, the other in \slshape. Additionally, the difference is at the end of paragraph 1, with "xyz" in one version and "XYZ" in the other; and the itemize environment with "A B" as the labels in one, and "1 2" as the labels in the other.

\documentclass{article}
\usepackage[nopar]{lipsum}
\usepackage{stackengine}
\usepackage{xcolor}
\def\stacktype{L}\def\stackalignment{l}
\begin{document}
\setbox0=\vbox{\color{red!90}\slshape%
\lipsum[1]xyz

\begin{itemize}
\item[A] \lipsum[3]

\item[B] \lipsum[4]
\end{itemize}
}
\setbox1=\vbox{\color{blue!40}%
\lipsum[1]XYZ

\begin{itemize}
\item[1] \lipsum[3]

\item[2] \lipsum[4]
\end{itemize}
}
\savestack{\first}{\box0}
\savestack{\second}{\box1}
\noindent\stackunder[0pt]{\first}{\second}
\end{document}


• @StevenSegletes I haven't seen the stackengine package before; this solution intrigues me, even if it doesn't quite include all the pieces I'd like (notably, missing the full-page background that would be necessary). I have some more reading to do! This seems cleaner than rendering each line in its own tikz node. Apr 5 '14 at 1:58