我正在尝试用 multicol 实现一个覆盖页面上两列之一的背景彩色矩形,并且该矩形正好位于纸张的边缘。
我对 background 包的 \backgroundsetup 命令中的 position= 选项感到困惑,因为它似乎与页面的下角没有任何关系。在下面的示例中,我尝试调整矩形的宽度以考虑边距。尽管 y 位置为零,但垂直位置似乎位于页面的中间。我显然误解了这里的东西,但我看不出是什么。
\PassOptionsToPackage{svgnames}{xcolor}
\documentclass{report}
\usepackage{lipsum,multicol,calc}
\usepackage[a4paper,twoside,
textheight=240mm,footskip=25mm,
inner=20mm,outer=35mm,top=15mm, nohead]{geometry}
\usepackage[pages=some]{background}
\usepackage[svgnames]{xcolor}
\setlength{\columnsep}{10mm}
\AtBeginDocument{%
\raggedright
\parskip=\baselineskip
\parindent=0pt}
\newlength{\bgwidth}% calculated width of rectangle
\newlength{\bgxpos}% calculated location of x-position
\makeatletter
\newcommand{\leftcolbackground}{% try to make it work L and R
\ifodd\c@page
\setlength{\bgxpos}{20mm}%
\setlength{\bgwidth}{\bgxpos + \oddsidemargin}%
\else
\setlength{\bgxpos}{35mm}%
\setlength{\bgwidth}{\bgxpos + \evensidemargin}%
\fi
\addtolength{\bgwidth}{\columnwidth}% assumes we are inside multicols
\typeout{columnwidth=\the\columnwidth, bgxpos=\the\bgxpos,
bgwidth=\the\bgwidth}%
\def\colbg{%
\begin{tikzpicture}
\fill[yellow] (0,0) rectangle (\bgwidth,\paperheight);
\end{tikzpicture}}%
\backgroundsetup{scale=1,color=black,opacity=1,
angle=0,position={\bgxpos,0},contents=\colbg}
\BgThispage}
\makeatother
\listfiles
\begin{document}
\chapter{Introduction}
\begin{multicols}{2}
\lipsum[1]
\lipsum[2]
\lipsum[3]
\lipsum[4]
\lipsum[5]
\lipsum[6]
\lipsum[7]
\lipsum[8]
\lipsum[9]
\lipsum[10]
\leftcolbackground
\section{This is a demo}
\lipsum[11]
\lipsum[12]
\subsection{Increasing the uptake of STEM candidates}
\lipsum[13]
\lipsum[14]
\section{This is another demo}
\lipsum[15]
\lipsum[16]
\lipsum[17]
\lipsum[18]
\subsection{More subtitling}
\lipsum[19]
\lipsum[20]
\lipsum[21]
\lipsum[22]
\end{multicols}
\end{document}
答案1
我建议先从
\backgroundsetup{scale=1,color=black,opacity=1,contents=\colbg,
angle=0,position=current page.south,nodeanchor=south east}
或者
\backgroundsetup{scale=1,color=black,opacity=1,contents=\colbg,
angle=0,position=current page.south,nodeanchor=south west}
将矩形放入定义的位置,然后使用hshift=...
或移动它vshift=...
,就像
\backgroundsetup{scale=1,color=black,opacity=1,contents=\colbg,
angle=0,position=current page.south,nodeanchor=south east,hshift=1in}
以下是这三个设置的输出。
答案2
使用覆盖层,您可以定位tikzpicture
相对于页面的位置:
\PassOptionsToPackage{svgnames}{xcolor}
\documentclass{report}
\usepackage{lipsum,multicol,calc}
\usepackage[a4paper,twoside,
textheight=240mm,footskip=25mm,
inner=20mm,outer=35mm,top=15mm, nohead]{geometry}
\usepackage[pages=some]{background}
\usepackage[svgnames]{xcolor}
\setlength{\columnsep}{10mm}
\AtBeginDocument{%
\raggedright
\parskip=\baselineskip
\parindent=0pt}
\newlength{\bgwidth}% calculated width of rectangle
\makeatletter
\newcommand{\leftcolbackground}{%
\setlength{\bgwidth}{\dimexpr\marginparwidth+.5\marginparsep+.5\textwidth}
\ifodd\c@page
\addtolength{\bgwidth}{\oddsidemargin}
\else
\addtolength{\bgwidth}{\evensidemargin}
\fi
\def\colbg{%
\tikz[overlay]{
\fill[yellow] (current page.north west) ++(\bgwidth,0) rectangle (current page.south west);
}
}
\backgroundsetup{scale=1,opacity=1,angle=0,contents=\colbg}
\BgThispage
}
\makeatother
\listfiles
\begin{document}
\chapter{Introduction}
\begin{multicols}{2}
\leftcolbackground
\lipsum[1]
\lipsum[2]
\lipsum[3]
\lipsum[4]
\lipsum[5]
\lipsum[6]
\lipsum[7]
\lipsum[8]
\lipsum[9]
\lipsum[10]
\leftcolbackground
\section{This is a demo}
\lipsum[11]
\lipsum[12]
\subsection{Increasing the uptake of STEM candidates}
\lipsum[13]
\lipsum[14]
\section{This is another demo}
\lipsum[15]
\lipsum[16]
\lipsum[17]
\lipsum[18]
\subsection{More subtitling}
\lipsum[19]
\lipsum[20]
\lipsum[21]
\lipsum[22]
\end{multicols}
\end{document}