I need to set a background color in about 50 pages of my document, but
for the main text only. The footnotes should be set without this
background color.
Using the usual macros, I can set the background for an entire page or
document (which gives footnotes the same background), or enclose text
within boxes, frames, or minipages, which can mess up footnotes or the
page breaking algorithm.
I've tried playing with the output routines a bit, but perhaps someone
already has a solution. Any suggestions would be appreciated.
CVR
|
|
0
|
|
|
|
Reply
|
CVR
|
12/29/2009 6:08:19 AM |
|
CVR <arnnvssb@gmail.com> writes:
> I need to set a background color in about 50 pages of my document, but
> for the main text only. The footnotes should be set without this
> background color.
>
> Using the usual macros, I can set the background for an entire page or
> document (which gives footnotes the same background), or enclose text
> within boxes, frames, or minipages, which can mess up footnotes or the
> page breaking algorithm.
>
> I've tried playing with the output routines a bit, but perhaps someone
> already has a solution. Any suggestions would be appreciated.
stupid idea: give entire page a color, then draw white box with and
below footnote line?
g.
|
|
0
|
|
|
|
Reply
|
Gaius
|
12/29/2009 11:59:47 PM
|
|
CVR <arnnvssb@gmail.com> wrote:
> I need to set a background color in about 50 pages of my document, but
> for the main text only. The footnotes should be set without this
> background color.
>
> Using the usual macros, I can set the background for an entire page or
> document (which gives footnotes the same background), or enclose text
> within boxes, frames, or minipages, which can mess up footnotes or the
> page breaking algorithm.
>
> I've tried playing with the output routines a bit, but perhaps someone
> already has a solution. Any suggestions would be appreciated.
The following solution uses \pdfsavepos, provided by pdfTeX/LuaTeX
(both DVI and PDF mode) and XeTeX. It redefines \@makecol to
get to the position of the footnote rule.
\documentclass{article}
%%% Background Color For Main Text %%%
\usepackage{atbegshi}
\usepackage{zref-abspage,zref-savepos}
\usepackage{color}
\makeatletter
\newif\ifbcfmt@pos
\CheckCommand*{\@makecol}{%
\ifvoid\footins
\setbox\@outputbox\box\@cclv
\else
\setbox\@outputbox\vbox{%
\boxmaxdepth \@maxdepth
\unvbox\@cclv
\vskip\skip\footins
\color@begingroup
\normalcolor
\footnoterule
\unvbox\footins
\color@endgroup
}%
\fi
\let\@elt\relax
\xdef\@freelist{\@freelist\@midlist}%
\global\let\@midlist\@empty
\@combinefloats
\ifvbox\@kludgeins
\@makespecialcolbox
\else
\setbox\@outputbox\vbox to\@colht{%
\@texttop
\dimen@\dp\@outputbox
\unvbox\@outputbox
\vskip -\dimen@
\@textbottom
}%
\fi
\global\maxdepth\@maxdepth
}
\renewcommand*{\@makecol}{%
\ifvoid\footins
\setbox\@outputbox\box\@cclv
\else
\setbox\@outputbox\vbox{%
\boxmaxdepth \@maxdepth
\unvbox\@cclv
\vskip\skip\footins
\color@begingroup
\normalcolor
\let\bcfmt@org@hrule\hrule
\def\hrule{%
\zsavepos{bcfmt@\the\numexpr\value{abspage}+1}%
\global\bcfmt@postrue
\bcfmt@org@hrule
}%
\footnoterule
\unvbox\footins
\color@endgroup
}%
\fi
\let\@elt\relax
\xdef\@freelist{\@freelist\@midlist}%
\global\let\@midlist\@empty
\@combinefloats
\ifvbox\@kludgeins
\@makespecialcolbox
\else
\setbox\@outputbox\vbox to\@colht{%
\@texttop
\dimen@\dp\@outputbox
\unvbox\@outputbox
\vskip -\dimen@
\@textbottom
}%
\fi
\global\maxdepth\@maxdepth
}
\AtBeginShipout{%
\ifx\bcfmt@color\@empty
\else
\AtBeginShipoutUpperLeft{%
\edef\bcfmt@x{%
\strip@pt\dimexpr
\@ifundefined{pdfhorigin}{1in}{\pdfhorigin}%
+\ifodd\value{page}\oddsidemargin\else\evensidemargin\fi
}%
\edef\bcfmt@y{%
\strip@pt\dimexpr
\@ifundefined{pdfvorigin}{1in}{\pdfvorigin}%
+\topmargin
+\headheight
+\headsep
}%
\put(\bcfmt@x,-\bcfmt@y){%
\makebox(0,0)[lt]{%
\let\current@color\bcfmt@color
\set@color
\edef\bcfmt@refname{bcfmt@\number\value{abspage}}%
\ifbcfmt@pos
\zref@refused{\bcfmt@refname}%
\fi
\rule{\textwidth}{%
\ifbcfmt@pos
\dimexpr
\zref@ifrefundefined{\bcfmt@refname}{%
\textheight
}{%
\@ifundefined{pdfpageheight}{%
\paperheight
}{%
\ifdim\pdfpageheight=\z@
\ht\AtBeginShipoutBox
+\dp\AtBeginShipoutBox
+\voffset
+2in
\else
\pdfpageheight
-\voffset
\fi
}%
-\zposy{\bcfmt@refname}sp%
-\bcfmt@y pt%
}%
\relax
\else
\textheight
\fi
}%
}%
}%
}%
\fi
\global\bcfmt@posfalse
}
\def\set@page@color{%
\global\let\bcfmt@color\current@color
}
\def\nopagecolor{%
\global\let\bcfmt@color\@empty
}
\nopagecolor
\makeatother
%%%%%%
\pagecolor{yellow}
\begin{document}
\tableofcontents
\section{Section}
Hello World\footnote{Some text}
\newpage
\section{Second section}
\vspace{\fill}
Bottom text line
\newpage
\nopagecolor
\section{Third section without background color}
\vspace{\fill}
Bottom text line
\newpage
\pagecolor{red}
\section{Section with two footnotes}
Hello\footnote{Text for hello}
World\footnote{Text for world}
\par
\vspace{\fill}
\noindent
Bottom text line
\end{document}
Yours sincerely
Heiko <oberdiek@uni-freiburg.de>
|
|
0
|
|
|
|
Reply
|
Heiko
|
12/30/2009 2:52:22 AM
|
|
Dear Heiko,
This is fantastic! It works beautifully.
Thanks very much for your help!
CVR
On Dec 29, 6:52=A0pm, Heiko Oberdiek <oberd...@uni-freiburg.de> wrote:
> CVR <arnnv...@gmail.com> wrote:
> > I need to set a background color in about 50 pages of my document, but
> > for the main text only. The footnotes should be set without this
> > background color.
>
> > Using the usual macros, I can set the background for an entire page or
> > document (which gives footnotes the same background), or enclose text
> > within boxes, frames, or minipages, which can mess up footnotes or the
> > page breaking algorithm.
>
> > I've tried playing with the output routines a bit, but perhaps someone
> > already has a solution. Any suggestions would be appreciated.
>
> The following solution uses \pdfsavepos, provided by pdfTeX/LuaTeX
> (both DVI and PDF mode) and XeTeX. It redefines \@makecol to
> get to the position of the footnote rule.
>
> \documentclass{article}
>
> %%% Background Color For Main Text %%%
>
> \usepackage{atbegshi}
> \usepackage{zref-abspage,zref-savepos}
> \usepackage{color}
>
> \makeatletter
> \newif\ifbcfmt@pos
> \CheckCommand*{\@makecol}{%
> =A0 \ifvoid\footins
> =A0 =A0 \setbox\@outputbox\box\@cclv
> =A0 \else
> =A0 =A0 \setbox\@outputbox\vbox{%
> =A0 =A0 =A0 \boxmaxdepth \@maxdepth
> =A0 =A0 =A0 \unvbox\@cclv
> =A0 =A0 =A0 \vskip\skip\footins
> =A0 =A0 =A0 \color@begingroup
> =A0 =A0 =A0 =A0 \normalcolor
> =A0 =A0 =A0 =A0 \footnoterule
> =A0 =A0 =A0 =A0 \unvbox\footins
> =A0 =A0 =A0 \color@endgroup
> =A0 =A0 }%
> =A0 \fi
> =A0 \let\@elt\relax
> =A0 \xdef\@freelist{\@freelist\@midlist}%
> =A0 \global\let\@midlist\@empty
> =A0 \@combinefloats
> =A0 \ifvbox\@kludgeins
> =A0 =A0 \@makespecialcolbox
> =A0 \else
> =A0 =A0 \setbox\@outputbox\vbox to\@colht{%
> =A0 =A0 =A0 \@texttop
> =A0 =A0 =A0 \dimen@\dp\@outputbox
> =A0 =A0 =A0 \unvbox\@outputbox
> =A0 =A0 =A0 \vskip -\dimen@
> =A0 =A0 =A0 \@textbottom
> =A0 =A0 }%
> =A0 \fi
> =A0 \global\maxdepth\@maxdepth}
>
> \renewcommand*{\@makecol}{%
> =A0 \ifvoid\footins
> =A0 =A0 \setbox\@outputbox\box\@cclv
> =A0 \else
> =A0 =A0 \setbox\@outputbox\vbox{%
> =A0 =A0 =A0 \boxmaxdepth \@maxdepth
> =A0 =A0 =A0 \unvbox\@cclv
> =A0 =A0 =A0 \vskip\skip\footins
> =A0 =A0 =A0 \color@begingroup
> =A0 =A0 =A0 =A0 \normalcolor =A0
> =A0 =A0 =A0 =A0 \let\bcfmt@org@hrule\hrule
> =A0 =A0 =A0 =A0 \def\hrule{%
> =A0 =A0 =A0 =A0 =A0 \zsavepos{bcfmt@\the\numexpr\value{abspage}+1}%
> =A0 =A0 =A0 =A0 =A0 \global\bcfmt@postrue
> =A0 =A0 =A0 =A0 =A0 \bcfmt@org@hrule
> =A0 =A0 =A0 =A0 }%
> =A0 =A0 =A0 =A0 \footnoterule
> =A0 =A0 =A0 =A0 \unvbox\footins
> =A0 =A0 =A0 \color@endgroup =A0
> =A0 =A0 }%
> =A0 \fi
> =A0 \let\@elt\relax
> =A0 \xdef\@freelist{\@freelist\@midlist}%
> =A0 \global\let\@midlist\@empty
> =A0 \@combinefloats
> =A0 \ifvbox\@kludgeins
> =A0 =A0 \@makespecialcolbox
> =A0 \else
> =A0 =A0 \setbox\@outputbox\vbox to\@colht{%
> =A0 =A0 =A0 \@texttop
> =A0 =A0 =A0 \dimen@\dp\@outputbox
> =A0 =A0 =A0 \unvbox\@outputbox
> =A0 =A0 =A0 \vskip -\dimen@
> =A0 =A0 =A0 \@textbottom
> =A0 =A0 }%
> =A0 \fi
> =A0 \global\maxdepth\@maxdepth}
>
> \AtBeginShipout{%
> =A0 \ifx\bcfmt@color\@empty
> =A0 \else
> =A0 =A0 \AtBeginShipoutUpperLeft{%
> =A0 =A0 =A0 \edef\bcfmt@x{%
> =A0 =A0 =A0 =A0 \strip@pt\dimexpr
> =A0 =A0 =A0 =A0 =A0 \@ifundefined{pdfhorigin}{1in}{\pdfhorigin}%
> =A0 =A0 =A0 =A0 =A0 +\ifodd\value{page}\oddsidemargin\else\evensidemargin=
\fi
> =A0 =A0 =A0 }%
> =A0 =A0 =A0 \edef\bcfmt@y{%
> =A0 =A0 =A0 =A0 \strip@pt\dimexpr
> =A0 =A0 =A0 =A0 =A0 \@ifundefined{pdfvorigin}{1in}{\pdfvorigin}%
> =A0 =A0 =A0 =A0 =A0 +\topmargin
> =A0 =A0 =A0 =A0 =A0 +\headheight
> =A0 =A0 =A0 =A0 =A0 +\headsep =A0
> =A0 =A0 =A0 }%
> =A0 =A0 =A0 \put(\bcfmt@x,-\bcfmt@y){%
> =A0 =A0 =A0 =A0 \makebox(0,0)[lt]{%
> =A0 =A0 =A0 =A0 =A0 \let\current@color\bcfmt@color
> =A0 =A0 =A0 =A0 =A0 \set@color
> =A0 =A0 =A0 =A0 =A0 \edef\bcfmt@refname{bcfmt@\number\value{abspage}}%
> =A0 =A0 =A0 =A0 =A0 \ifbcfmt@pos
> =A0 =A0 =A0 =A0 =A0 =A0 \zref@refused{\bcfmt@refname}%
> =A0 =A0 =A0 =A0 =A0 \fi
> =A0 =A0 =A0 =A0 =A0 \rule{\textwidth}{%
> =A0 =A0 =A0 =A0 =A0 =A0 \ifbcfmt@pos
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 \dimexpr =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \zref@ifrefundefined{\bcfmt@refname}{%
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \textheight
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }{%
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \@ifundefined{pdfpageheight}{%
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \paperheight
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }{%
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \ifdim\pdfpageheight=3D\z@
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \ht\AtBeginShipoutBox
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 +\dp\AtBeginShipoutBox
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 +\voffset
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 +2in
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \else
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \pdfpageheight
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -\voffset
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \fi
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }% =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -\zposy{\bcfmt@refname}sp%
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -\bcfmt@y pt%
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }%
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 \relax
> =A0 =A0 =A0 =A0 =A0 =A0 \else =A0
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 \textheight
> =A0 =A0 =A0 =A0 =A0 =A0 \fi
> =A0 =A0 =A0 =A0 =A0 }% =A0
> =A0 =A0 =A0 =A0 }% =A0 =A0
> =A0 =A0 =A0 }% =A0 =A0 =A0
> =A0 =A0 }% =A0 =A0 =A0 =A0
> =A0 \fi =A0 =A0 =A0 =A0 =A0
> =A0 \global\bcfmt@posfalse}
>
> \def\set@page@color{%
> =A0 \global\let\bcfmt@color\current@color}
>
> \def\nopagecolor{%
> =A0 \global\let\bcfmt@color\@empty}
>
> \nopagecolor
> \makeatother
>
> %%%%%%
>
> \pagecolor{yellow}
>
> \begin{document}
> \tableofcontents
> \section{Section}
> Hello World\footnote{Some text}
> \newpage
> \section{Second section}
> \vspace{\fill}
> Bottom text line
> \newpage
> \nopagecolor
> \section{Third section without background color}
> \vspace{\fill}
> Bottom text line
> \newpage
> \pagecolor{red}
> \section{Section with two footnotes}
> Hello\footnote{Text for hello}
> World\footnote{Text for world}
> \par
> \vspace{\fill}
> \noindent
> Bottom text line
> \end{document} =A0
>
> Yours sincerely
> =A0 Heiko <oberd...@uni-freiburg.de>
|
|
0
|
|
|
|
Reply
|
CVR
|
12/31/2009 6:42:20 PM
|
|
|
3 Replies
131 Views
(page loaded in 0.103 seconds)
|