我想编写一个 LaTeX 文档,并且我想有文档规则(彩色边距区分章节和/或偶数/奇数页)。
以下是我心中的模型:
如何实现这一点?
我见过这个问题这是与我心中的想法最相关的问题,但它并没有完全实现我的目标。
我也在 Google 上搜索过,我能想到的最好的办法是使用“framed”包,但这同样不能完成这项任务。不过,我相信这是可以做到的。
答案1
以下是基于以下软件包的可能解决方案:
请注意,需要运行两次编译才能成功为边距着色。
代码:
\documentclass{article}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\usepackage{ifthen}
\usepackage[contents={},opacity=1,scale=1.485]{background}
\AddEverypageHook{%
\ifthenelse{\isodd{\thepage}}%
{\backgroundsetup{angle=0,position={0.9\textwidth,-
.7\textheight},%
contents={\tikz[remember picture,overlay]{ %
\coordinate (x) at (current page marginpar area.south east|-current page.south east);
\draw[draw=none,fill=magenta!20]([xshift=-\textwidth]x)rectangle(current page.north west);}}}}%
{\backgroundsetup{angle=0,position={0.9\textwidth,-
.7\textheight},%
contents={\tikz[remember picture,overlay]{ %
\coordinate (x) at (current page marginpar area.south east|-current page.south east);
\draw[draw=none,fill=orange!20](x)rectangle(current page.north east);}}}}%
\BgMaterial}
\usepackage{lipsum} % dummy text
\begin{document}
\lipsum[1-30]
\end{document}
结果(仅显示前两页):
答案2
我认为这个tikz
解决方案很棒,并且可能允许许多复杂的模式,但如果您只想要一个简单的条形图,那么就不需要它了。
下面的解决方案采用:
xcolor
对于颜色eso-pic
用于每页的背景(这是background
包裹)ifthen
for 条件语句
平均能量损失
\documentclass{article}
\usepackage{xcolor} % to have colors
\usepackage{eso-pic} % put things into background
\usepackage{lipsum} % for sample text
\usepackage{ifthen}
\AddToShipoutPicture{% from package eso-pic: put something to the background
\ifthenelse{\isodd{\thepage}}{
% ODD page: left bar
\AtPageLowerLeft{% start the bar at the left bottom of the page
\color{blue}\rule{2cm}{\LenToUnit\paperheight}%
}%
}%
{%
% EVEN page: right bar
\AtPageLowerLeft{% start the bar at the bottom right of the page
\put(\LenToUnit{\dimexpr\paperwidth-3cm},0){% move it to the top right
\color{orange}\rule{3cm}{\LenToUnit\paperheight}%
}%
}%
}%
}
\begin{document}
\lipsum
\lipsum
\lipsum
\end{document}
以下是对未来有用的参考:
答案3
没有答案和fancyhdr
!tikz
。让我插话:
\documentclass[twoside]{article}
\usepackage{tikz} % you know what this does!
\usetikzlibrary{calc}
\usepackage{fancyhdr} % put things headers and footers and we plan misuse it ;)
\usepackage{lipsum} % for sample text
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LO]{%
\begin{tikzpicture}[overlay,remember picture]
\fill [color=blue]
(current page.north west)
rectangle
($ (current page.south west) + (1cm,0cm) $);
\end{tikzpicture}
}
\fancyhead[RE]{%
\begin{tikzpicture}[overlay,remember picture]
\fill [color=orange]
(current page.north east)
rectangle
($ (current page.south east) + (-1cm,0cm) $);
\end{tikzpicture}
}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\begin{document}
\lipsum
\lipsum
\lipsum
\end{document}