7

I am doing my project report using latex, and the format requires a particular kind of page border around each page. (Its a black thick box enclosing a thin box).

I saw this question, Multiple border around page

and adapted it to get the required border using this example:

\documentclass[a4paper,12pt,oneside]{memoir}

\usepackage{lmodern} % Latin Modern font package
\usepackage[T1]{fontenc}

\usepackage{amssymb,amsmath}
\usepackage{graphicx}
\usepackage{url}
\usepackage{marvosym}
\usepackage{float}

% Metadata
\title{My Project}
\author{Philips George John}
\date{April 2013}

% Options for the memoir class
% Page Margins
\setulmarginsandblock{1in}{1in}{*}
\setlrmarginsandblock{1.4in}{1in}{*}

% Paragraph formatting for memoir class
\nonzeroparskip

% Get subfloats in figure environment
\newsubfloat{figure}

% Tells memoir to recalculate all parameters
% Apply and enforce our new layout
\checkandfixthelayout

% Page border
\usepackage{background}
\usetikzlibrary{calc}
\SetBgScale{1}
\SetBgAngle{0}
\SetBgColor{black}
\SetBgContents{
\begin{tikzpicture}[overlay,remember picture]
\draw [line width=3pt]
    ($ (current page.north west) + (2.0cm,-2.0cm) $)
    rectangle
    ($ (current page.south east) + (-1.5cm,1.8cm) $);
\draw [line width=1pt]
    ($ (current page.north west) + (2.15cm,-2.15cm) $)
    rectangle
    ($ (current page.south east) + (-1.65cm,1.95cm) $); 
\end{tikzpicture}
}

\begin{document}

\frontmatter
\maketitle
\thispagestyle{empty}

\mainmatter
\chapter{Introduction}
\section{Section A}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue 
massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, 
sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim.

\clearpage
\section {Section B}
In porttitor. Donec laoreet nonummy augue. Suspendisse dui purus, scelerisque at, 
vulputate vitae, pretium mattis, nunc. Mauris eget neque at sem venenatis eleifend.
Ut nonummy. Fusce aliquet pede non pede.
\end{document}

I could get the output, and the borders are "shaped" correctly. But I have two problems.

1) The borders appear in gray colour. They are supposed to be black. Specifying the colour "black" with \draw command did not help.

2) For some reason, I need to run pdflatex three times to get the output correctly. First time it shows no border. Second time, it shows a border placed incorrectly. When I compile it for the third time, it shows correctly (except for the colour).

Forgive me if this question is very obvious, but I am new to LaTeX.

2 Answers2

5
  1. You need to set the value for opacity to 1 (the default value is 0.5).

  2. This is not a problem; it's the standard behaviour, since some calculations are internally performed and then the material is placed in the chosen location.

Your example code, with the value for opacity:

\documentclass[a4paper,12pt,oneside]{memoir}

\usepackage{lmodern} % Latin Modern font package
\usepackage[T1]{fontenc}

\usepackage{amssymb,amsmath}
\usepackage{graphicx}
\usepackage{url}
\usepackage{marvosym}
\usepackage{float}

% Metadata
\title{My Project}
\author{Philips George John}
\date{April 2013}

% Options for the memoir class
% Page Margins
\setulmarginsandblock{1in}{1in}{*}
\setlrmarginsandblock{1.4in}{1in}{*}

% Paragraph formatting for memoir class
\nonzeroparskip

% Get subfloats in figure environment
\newsubfloat{figure}

% Tells memoir to recalculate all parameters
% Apply and enforce our new layout
\checkandfixthelayout

% Page border
\usepackage{background}
\usetikzlibrary{calc}
\SetBgScale{1}
\SetBgAngle{0}
\SetBgColor{black}
\SetBgOpacity{1}
\SetBgContents{
\begin{tikzpicture}[overlay,remember picture]
\draw [line width=3pt]
    ($ (current page.north west) + (2.0cm,-2.0cm) $)
    rectangle
    ($ (current page.south east) + (-1.5cm,1.8cm) $);
\draw [line width=1pt]
    ($ (current page.north west) + (2.15cm,-2.15cm) $)
    rectangle
    ($ (current page.south east) + (-1.65cm,1.95cm) $); 
\end{tikzpicture}
}

\begin{document}

\frontmatter
\maketitle
\thispagestyle{empty}

\mainmatter
\chapter{Introduction}
\section{Section A}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue 
massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, 
sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim.

\clearpage
\section {Section B}
In porttitor. Donec laoreet nonummy augue. Suspendisse dui purus, scelerisque at, 
vulputate vitae, pretium mattis, nunc. Mauris eget neque at sem venenatis eleifend.
Ut nonummy. Fusce aliquet pede non pede.
\end{document}

An image of the first page of the resulting document:

enter image description here

By the way, with the most recent version of the package you can use a key,option mechanism and \backgroundsetup (for compatibility, the new version also admits the \SetBg.... syntax):

\usepackage{background}
\usetikzlibrary{calc}
\backgroundsetup{
scale=1,
angle=0,
color=black,
opacity=1,
contents={
\begin{tikzpicture}[overlay,remember picture]
\draw [line width=3pt]
    ($ (current page.north west) + (2.0cm,-2.0cm) $)
    rectangle
    ($ (current page.south east) + (-1.5cm,1.8cm) $);
\draw [line width=1pt]
    ($ (current page.north west) + (2.15cm,-2.15cm) $)
    rectangle
    ($ (current page.south east) + (-1.65cm,1.95cm) $); 
\end{tikzpicture}
}
}
Gonzalo Medina
  • 505,128
5

You can also use the tikzpagenodes package, which will result in a solution independant of the margins you chose:

Code

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{background}
\usetikzlibrary{calc}
\usepackage{tikzpagenodes}
\usepackage{lipsum}

\backgroundsetup%
{   contents={
        \begin{tikzpicture}[overlay]
            \draw[black] ($(current page text area.south west)+(-0.1,-0.1)$) rectangle ($(current page text area.north east)+(0.1,0.1)$);
            \draw[black,very thick] ($(current page text area.south west)+(-0.25,-0.25)$) rectangle ($(current page text area.north east)+(0.25,0.25)$);
        \end{tikzpicture}
    },
    scale=1,
    angle=0
}

\begin{document}

\lipsum

\end{document}

Output

enter image description here

Tom Bombadil
  • 40,123