我有以下文件
\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}
我无法将背景层(即两个矩形边框)放在背景中。我的代码有什么问题?我在 eclipse 中使用 texlipse,在 pdflatex 中使用 miktex
期望的输出是在页面周围放置两个矩形。由于我有很多文件 1、文件 2,如果 \input 命令保留在那里,我将不胜感激。
答案1
这是一个带有后台包的解决方案。
\newframe
将背景\Noframe
打开并关闭。
\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}
编辑:这是一个仅用于测试的简单代码
\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}
首先:您需要\Noframe
命令来关闭草稿背景,然后\newframe
打开矩形背景。
\newframe
如果您需要第一页的背景,可以直接使用。
您还可以添加contents={}
到背景包的选项
\usepackage[
contents=,
placement=top,
opacity=1,
scale=1,
anchor= below,
vshift=-.9in, hshift=.6cm
]{background}
那么就不会有草稿背景了。