编辑

编辑

因此,本练习的目标是使文本能够通过ocg-p包以两种不同的样式显示,具体取决于有效的 OCG 层(与此问题/答案类似)。 这个问题的核心是将同一文本的两个版本排版在一起;OCG 是不是我的问题出在哪里。

问题:

我有两种风格需要分层。 我如何才能以两种不同的样式在页面上的相同位置排版相同的内容? 也就是说,我知道如何在同一空间内以小规模排版事物,也许是这样的:

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

This is completely separate.

但...对于多行、整页环境,我该如何进行上述操作?

注意,我的其他问题特指从解决ocg-p问题的角度来解决这个问题。这个问题是关于将内容排版两次,采用两种样式,相互叠加。

为了获得所需的效果,我需要在页面上的同一位置使用单色样式和彩色样式创建一个 OCG 包装环境。我想在两个位置执行此操作:

  1. 标题页(整页)
  2. 章节标题

应将彩色样式作为基础层呈现,而黑白样式应通过 OCG 叠加在彩色样式之上。OCG 将用于呈现黑白层,因此默认情况下它不会显示,但始终会打印(如下所示)。这将允许优雅降级,黑白版本既显示在屏幕上,又可以在不兼容 OCG 的 PDF 查看器中打印(几乎除了 Adob​​e 之外的任何查看器...)。

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

示例样式

彩色与黑白标题页

标题颜色 标题bw

彩色与黑白节标题

部分颜色 部分bw

平均能量损失

此代码显示了我想要分层为静态版本的两种样式,这些样式通过命名的状态来区分boolusecolor此变量是预先设置的,文档按照设置的样式进行排版:

\setbool{usecolor}{false}

完整示例:

\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
\usepackage[margin=2.0cm,top=1.5cm,includehead,includefoot]{geometry}
\setlength{\headheight}{15pt}

%%%% 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}

答案1

这厚颜无耻地抄袭了 cslstr 为各部分发布的解决方案,并将其也应用于标题页。请注意,我在重写时非常小心,\MyTitle以确保格式正确,但标题页元素的间距有非常小的变化。如果这是一个问题,显然可以进行进一步的调整,但在我看来,对于几乎所有实际用途来说,这看起来“足够接近”。

警告:我不知道这应该如何在 pdf 查看器中显示。在 中acroread,我可以切换到单色层,并为标题页和章节标题获取单色。在 Okular 中,单色似乎不适用于标题页或章节标题。因此,我假设它应该是这样的,因为您说章节标题解决方案有效,而我的标题页代码似乎以相同的方式运行。但在您发布这个问题之前,我从未听说过 OCG...

进一步警告:我的tikz技能仅比我对 OCG 的了解稍微有限一些......

买者自负!

\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
\usepackage[margin=2.0cm,top=1.5cm,includehead,includefoot]{geometry}
\setlength{\headheight}{15pt}

%%%% 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}

笔记:你真的应该geometry说说headheight。如果你在背后偷偷修改,破坏了它的努力,那么使用这个包就毫无意义了!

acroread标准层:

acroread:标准

acroread单色层:

acroread:单色

奥克拉:

奥克拉尔

编辑

如果您希望容纳多行标题,但准备手动指定换行符,您可以这样做:

\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
\usepackage[margin=2.0cm,top=1.5cm,includehead,includefoot]{geometry}
\setlength{\headheight}{15pt}

%%%% 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}

Okular 中的多行标题

如果您希望保持标题和线条之间的距离,而不是保持线条的位置不变,您可以尝试:

\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
\usepackage[margin=2.0cm,top=1.5cm,includehead,includefoot]{geometry}
\setlength{\headheight}{15pt}

%%%% 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}

另一个多行标题

答案2

以下 MWE 仅适用于第二部分 - 仅适用于部分标题设计。创建的 PDF 将在 Adob​​e 阅读器中打开,标题为彩色,但打印为黑白/单色。

梅威瑟:

\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[margin=2.0cm,top=1.5cm,includehead,includefoot]{geometry}
\setlength{\headheight}{15pt}

\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}

答案3

在这里,我试图回答 OP 的问题,“\rlap对于多行、全页环境,我该如何实现这个 [示例]?”我在这里做的是将两个版本保存在单独的\vboxes 中,然后将它们堆叠在一起。这种方法不会跨页,目前仅限于边距之间的内容,当然,后一种限制很可能可以解决。

在这个 MWE 中,我有两个几乎相同的构图,一个是红色,另一个是蓝色。一个在 中\upshape,另一个在 中\slshape。此外,差异在于第 1 段的末尾,一个版本中有“xyz”,另一个版本中有“XYZ”;并且 itemize 环境在一个版本中以“A B”作为标签,在另一个版本中以“1 2”作为标签。

\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}

在此处输入图片描述

在此处输入图片描述

相关内容