8

I've got a LaTeX document, and I've been given a PNG file consisting of a page border with a big transparent section in the middle.

Is it possible to use LaTeX to add that image to every page, with the actual content in the transparent section; or will I have to create the PDF with LaTeX and then manually add the border in some other way?

1 Answers1

8

One option would be to use the background package to place the image as a background image; the geometry package can be used to adjust the text area. A little example:

\documentclass{article}
\usepackage[tmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm,bmargin=2.5cm]{geometry}
\usepackage{graphicx}
\usepackage{background}
\usepackage{fourier}
\usepackage{lipsum}

\backgroundsetup{scale=1,angle=0,opacity=1,contents={\includegraphics[scale=1]{border}}}

\begin{document}
\lipsum[1-20]
\end{document}

An image of the first page of the resulting document:

enter image description here

Here's the code I used toproduce the border used:

\documentclass{article}
\usepackage[dvipsnames]{xcolor} 
\usepackage[object=vectorian]{pgfornament}
\usetikzlibrary{calc}

\definecolor{mycolor}{cmyk}{0,0,0.1,0}

\pagestyle{empty}
\begin{document}
\color{mycolor}
\begin{tikzpicture}[remember picture,overlay] 
\coordinate (a) at ( $ (current page.north west) +  (1cm,-1cm)$); 
\coordinate (b) at ( $ (current page.south west) +  (1cm,1cm)$); 
\coordinate (c) at ( $ (current page.south east) +  (-1cm,1cm)$); 
\coordinate (d) at ( $ (current page.north east) +  (-1cm,-1cm)$); 
\fill[Maroon] (current page.south west) rectangle ( $ (current page.north west) + (2cm,0) $);
\fill[Maroon] (current page.south east) rectangle ( $ (current page.north east) + (-2cm,0) $);
\fill[Maroon] (current page.north west) rectangle ( $ (current page.north east) + (0,-2cm) $);
\fill[Maroon] (current page.south west) rectangle ( $ (current page.south east) + (0,2cm) $);
\pgfornamenthline{a}{d}{north}{87}
\pgfornamenthline{b}{c}{south}{87}
\pgfornamentvline{a}{b}{west}{87}
\pgfornamentvline{c}{d}{east}{87} 
\end{tikzpicture}
\end{document}
Gonzalo Medina
  • 505,128
  • Do you know why this fails if babel is loaded with french? – cfr Apr 13 '14 at 20:32
  • @cfr is the problem of some babel modules making active some characters that TikZ uses. The quickest solution is to use the babel library: \usetikzlibrary{babel} (for version 3.0.0 of TikZ); other wise, you will need to use every picture/.append style to invoke \shorthandoff for the problematic charcater(s). – Gonzalo Medina Apr 13 '14 at 20:38
  • Thanks! Normally I only use 2 languages with babel and one is English while the other is, let's say, minimal in its support of anything. (Hyphenation patterns and a very few translations many of which are non-optimal is about it.) But I was trying to answer a question which used French and so surprised that turned out to be the problem. I guess there are advantages to using a radically under-supported language which does next-to-nothing after all! – cfr Apr 13 '14 at 20:56
  • @cfr yes; the spanish module, for example, tries to implement a lot of the Spanish rules dictated by our Real Academia and in doing so generates many incompatibilities with some packages (with TikZ, for example, but also with lipsum!); a non-experienced user can become really clueless as to where the problem might be. – Gonzalo Medina Apr 13 '14 at 21:06
  • I, on the other hand, have yet to come across a problem created by welsh other than mistranslations ;). Then again, the fact that the language is not supported by the T1 encoding, that translations are non-existent in most cases and that nothing else has ever heard of it is not unproblematic... [Or any other encoding. The only one which supports it is berenisadf in LY1.] – cfr Apr 13 '14 at 21:30
  • @cfr I have no experience with using Welsh in LaTeX; in fact, I just know very little about Welsh at all, though I must say I find it intriguing. To be fair with the spanish module author, I must add to my previous comment that he took the necessary precautions to circumvert the problems with the active characters and those are well documented in spanish.pdf; however, must users never read documentations :( – Gonzalo Medina Apr 13 '14 at 21:46
  • I hope Welsh will eventually be covered by polyglossia since I think that would help. Right now, no standard font encoding includes the accented characters required so they have to be composed which is, obviously, not optimal. (Unless you use berenisadf.) But it would also be nice to have more stuff work out-of-the-box... [Especially if I could be confident it was correct! It's my second language...] It needs a bunch of translations but it also needs a different sort order from English as the alphabet is different. [Weirdly, people often think Welsh must mean a variant of English!] – cfr Apr 13 '14 at 22:09
  • Should probably tidy up these comments shortly... – cfr Apr 13 '14 at 22:12