2

I have following document

\documentclass[a4paper,12pt]{report}
\usepackage[left=1.5in,right=1in,top=1in,bottom=1in,
 includefoot,heightrounded]{geometry}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage[document]{ragged2e}
\usepackage{multicol}
\usepackage{fancyhdr}    
\usepackage{etoolbox}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,backgrounds,shadows,calc}

\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\newcommand{\newframe}[0]
{   \begin{tikzpicture}[remember picture,overlay]
    \begin{pgfonlayer}{background}
    \draw [black,even odd rule] ($(current page.north
    west)+(1.5in,-1in)$) rectangle ($(current page.south east)+(-1in,1in)$);
    \draw [black,even odd rule] ($(current page.north
    west)+(1.45in,-0.95in)$) rectangle ($(current page.south east)+(-0.95in,0.95in)$);
    \end{pgfonlayer}
    \end{tikzpicture}
}

\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}

\begin{document}
\newframe
\input{file1.tex}
\pagenumbering{gobble}

\newpage
\newframe
\input{file2.tex}
\pagenumbering{gobble}
\end{document}

I am unable to put background layer (i.e. two rectangular borders) in background. What is wrong with my code? I am using texlipse in eclipse and miktex with pdflatex

Desired output is to put two square rectangles around page. Since i have lots of file1, file2 i would really appreciate if \input command stays there.

  • I am not applying $fancy pagestyle to any of input document – Prachil Tambe Apr 8 '15 at 18:33
  • What error are you getting? – Werner Apr 8 '15 at 18:39
  • your question is not clear. you want two rectangular in background of all pages? or just the 2 pages and you have a problem? what is the problem? – touhami Apr 8 '15 at 18:51
  • no error. only border which i desired to be in background is being shifted on new page instead. I am suspecting it has to do anything with 'overlay' but i don't know what. @touhami I need to apply background to each input file for each page regardless of number of pages. – Prachil Tambe Apr 8 '15 at 18:53
1

Here is a solution with background package.

\newframe for background on \Noframe bakgound off.

\documentclass[a4paper,12pt]{report}
\usepackage[left=1.5in,right=1in,top=1in,bottom=1in,
 includefoot,heightrounded]{geometry}
\usepackage[document]{ragged2e}
\usepackage{multicol}
\usepackage{fancyhdr}    
\usepackage{etoolbox}
\usepackage{tikz,lipsum}
\usetikzlibrary{shapes,arrows,backgrounds,shadows,calc}
\usepackage[
placement=top,
opacity=1,
scale=1,
anchor= below,
vshift=-.9in, hshift=.6cm
]{background}

\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}

\newcommand{\newframe}{%
\backgroundsetup{contents={%
\begin{tikzpicture}
    \draw [black,even odd rule] ($(current page.north
    west)+(1.5in,-1in)$) rectangle ($(current page.south east)+(-1in,1in)$);
    \draw [black,even odd rule] ($(current page.north
    west)+(1.45in,-0.95in)$) rectangle ($(current page.south east)+(-0.95in,0.95in)$);
    \end{tikzpicture}}}}

\newcommand{\Noframe}{%
\backgroundsetup{contents={}}}

\begin{document}
\newframe
\lipsum[1-5]
\pagenumbering{gobble}

\newpage
\Noframe
\lipsum[1-15]
\pagenumbering{gobble}
\newframe
\lipsum[1-5]
\end{document}

Edit: Here is a simple code just for test

\documentclass{report}
\usepackage{lipsum}     %just for dummy text

\usepackage[
placement=top,
opacity=1,
scale=1,
anchor= below,
vshift=-.9in, hshift=.6cm
]{background}

\usetikzlibrary{shapes,arrows,backgrounds,shadows,calc}

\newcommand{\newframe}{%
\backgroundsetup{contents={%
\begin{tikzpicture}
    \draw [black,even odd rule] ($(current page.north
    west)+(1.5in,-1in)$) rectangle ($(current page.south east)+(-1in,1in)$);
    \draw [black,even odd rule] ($(current page.north
    west)+(1.45in,-0.95in)$) rectangle ($(current page.south east)+(-0.95in,0.95in)$);
    \end{tikzpicture}}}}

\newcommand{\Noframe}{%
\backgroundsetup{contents={}}}

\begin{document}
\Noframe
\lipsum[1-15]
\newframe
\lipsum[1-5]
\Noframe
\lipsum[1-5]
\end{document}

First: you need \Noframe command to make the Draft background off and than \newframe to make rectangle background on.

you can use \newframe directly if you need background from the first page.

you can also add contents={} to the background package's option

\usepackage[
contents=,
placement=top,
opacity=1,
scale=1,
anchor= below,
vshift=-.9in, hshift=.6cm
]{background}

and then there will be no Draft background.

  • It prints 'Draft' in the background of each page but does not serves the purpose. Rectangles are still appearing on separate page than content. Can you provide me a solution where i can actually use a Tikz Drawing as background? – Prachil Tambe Apr 8 '15 at 19:41
  • @PrachilTambe did you try this code by copy paste? for me it work just fine. – touhami Apr 8 '15 at 20:23
  • @PrachilTambe answer edited – touhami Apr 8 '15 at 20:38
  • My background.sty does not contains any command called '\backgroundsetup' instead it contains '\SetBgContent' which allow me to set textual contents rather than TikZ contents. Please provide me link to your 'background.sty'. Thanks For your help – Prachil Tambe Apr 8 '15 at 21:38
  • ctan.org/pkg/background – touhami Apr 8 '15 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.