geometry-frames.sty

geometry-frames.sty

我无法同时执行这两个命令。它们各自独立工作。我还想将页码放在所有页面的右下角。有什么建议吗?

\documentclass{article}

\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{background}
\usepackage{graphicx}
\usepackage{lastpage}

%for black  frame on each page
% \usetikzlibrary{calc}
% \SetBgScale{1}
% \SetBgAngle{0}
% \SetBgColor{black}
% \SetBgOpacity{1}
% \SetBgContents{
% \begin{tikzpicture}[overlay,remember picture]
% \draw [line width=1.5pt]
%     ($ (current page.north west) + (0.4in,-0.4in) $)
%     rectangle
%     ($ (current page.south east) + (-0.4in,0.4in) $);
% \end{tikzpicture}}

%for logo on each page
\backgroundsetup{
  scale=1,
  color=black,
  opacity=1,
  angle=0,
  position=current page.south,
  vshift=1in,
  contents={%
  \small\sffamily
  \begin{minipage}{.18\textwidth}
 \includegraphics[width=\linewidth,height=25pt,keepaspectratio]{logo_cosinus.jpg} %logo goes here
  \end{minipage}%
  }
}

\begin{document}
\lipsum
\end{document}

答案1

这里有一个使用 的建议scrlayer-scrpage。然后您可以为框架声明一个新层,为徽标声明另一个新层。这些层可以添加到一个页面样式中,如scrheadings、等plainempty也可以添加到所有层页面样式中@everystyle@

我已经习惯\fbox插入框架所以无需加载tikz

\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}

\usepackage[manualmark]{scrlayer-scrpage}[2015/10/03]
\clearpairofpagestyles
\ofoot{\pagemark}

\DeclareNewLayer[
  background,
  voffset=.4in+.75pt,
  hoffset=.4in-.75pt,
  addwidth=-.8in-1.5pt,
  addheight=-.8in-1.5pt,
  mode=picture,
  contents={\putLL{%
    \setlength\fboxrule{1.5pt}\setlength\fboxsep{0pt}%
    \fbox{\parbox[b][\layerheight]{\layerwidth}{\mbox{}}}%
    }}]{frame}
\DeclareNewLayer[
  background,
  bottommargin,
  mode=picture,
  contents={\put(\LenToUnit{.5\layerwidth},\LenToUnit{1in}){%
    \includegraphics[width=.18\textwidth,height=25pt,keepaspectratio]{example-image.pdf}%
}}]{logo}

\AddLayersToPageStyle{@everystyle@}{frame,logo}

\begin{document}
\lipsum
\end{document}

在此处输入图片描述

答案2

虽然background是一个很好的包装underlay,但fancyhdr(例如)可以很好地在确定的位置显示页码。

\fancypagestyle{plain}{%
  \fancyfoot{} % Clear the footer
  \rfoot{\thepage} % set the page number at the right footer. 
}

原则上,可以使用 来设置图像,\cfoot{\includegraphics...}而不是使用background

代码如下:

\documentclass{article}

\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{background}
\usepackage{graphicx}
\usepackage{lastpage}

%for black  frame on each page
% \usetikzlibrary{calc}
% \SetBgScale{1}
% \SetBgAngle{0}
% \SetBgColor{black}
% \SetBgOpacity{1}
% \SetBgContents{
% \begin{tikzpicture}[overlay,remember picture]
% \draw [line width=1.5pt]
%     ($ (current page.north west) + (0.4in,-0.4in) $)
%     rectangle
%     ($ (current page.south east) + (-0.4in,0.4in) $);
% \end{tikzpicture}}

%for logo on each page
\backgroundsetup{
  scale=1,
  color=black,
  opacity=1,
  angle=0,
  position=current page.south,
  vshift=1in,
  contents={%
  \small\sffamily
  \begin{minipage}{.18\textwidth}
 \includegraphics[width=\linewidth,height=25pt,keepaspectratio]{beeduck.jpg} %logo goes here
  \end{minipage}%
  }
}
\fancypagestyle{plain}{%
  \fancyfoot{}
  \rfoot{\thepage}
}

\pagestyle{plain}
\begin{document}

\lipsum
\end{document}

在此处输入图片描述

答案3

为什么不把这两个动作放在一个块中呢?

\documentclass{article}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{background}
\usepackage{graphicx}
\usepackage{lastpage}

\pagestyle{fancy} 
\fancyhf{} %
\renewcommand{\headrulewidth}{0pt} % remove header rule
\renewcommand{\footrulewidth}{0pt} % remove footer rule
\fancyfoot[R]{\thepage}

%% For black  frame on each page + Logo
\usetikzlibrary{calc}
\SetBgScale{1}
\SetBgAngle{0}
\SetBgColor{black}
\SetBgOpacity{1}
\SetBgContents{
\begin{tikzpicture}[overlay,remember picture]
\draw [line width=1.5pt]
($ (current page.north west) + (0.4in,-0.4in) $)
rectangle
($ (current page.south east) + (-0.4in,0.4in) $);
\node at ([yshift=1in]current page.south){\includegraphics[width=\linewidth,height=25pt,keepaspectratio]{example-image}};
\end{tikzpicture}
}

\begin{document}
\lipsum
\end{document}

在此处输入图片描述

答案4

几何学能够显示框架以显示页面布局,以便进行调试。实际上,这没什么用,因为页面周围的框架不允许框架和文本之间有任何分隔,此外,它还绘制了一堆其他线条来标记页面布局的其他方面。

然而,我认为应该可以设计一个寄生包,它可以挂接到几何学的功能并以相同的方式添加更灵活定义的框架,或者除了包本身可用的调试标记之外。

本答案首先geometry-frames.sty以一个简单的例子进行说明。然后说明如何将其与问题中的代码相结合以满足三个要求(框架、徽标和页码)。

geometry-frames.sty

该包基于直接修改的代码geometry.sty并使用该包的机制将框架添加到页面。

用户界面提供以下命令:

  • \GeometryFrame[<margin around text>][<thickness of frame rule>]根据指定值或(如果未指定)默认值将框架添加到页面。默认值是5pt文本周围的边距和.4pt框架的规则。

  • \NoGeometryFrame关闭框架的添加。

这两个命令都会影响当前页面和所有后续页面。

以下是针对 A4 纸上双面布局的文档的演示,其中有 3 种设置:

\documentclass[a4paper,twoside]{article}
% \usepackage[showframe]{geometry}% for showing debugging layout frames provided by geometry
\usepackage{geometry-frames}
\begin{document}
\GeometryFrame
first first first first As any dedicated reader can clearly see, the Ideal of practical reason is a representation of, as far as I know, the things in themselves; as I have shown elsewhere, the phenomena should only be used as a canon for our understanding.
\newpage
\GeometryFrame[5pt][10pt]
first first first first As any dedicated reader can clearly see, the Ideal of practical reason is a representation of, as far as I know, the things in themselves; as I have shown elsewhere, the phenomena should only be used as a canon for our understanding.
\newpage
\NoGeometryFrame
first first first first As any dedicated reader can clearly see, the Ideal of practical reason is a representation of, as far as I know, the things in themselves; as I have shown elsewhere, the phenomena should only be used as a canon for our understanding.
\end{document}

演示

如果我们添加几何学的调试框架显示布局,我们可以更详细地看到正在发生的事情:

带有布局标记的演示

插图

转到问题中提供的代码,这是第一次尝试使用新命令向具有所需特征的页面添加框架。

我们首先加载包。

\usepackage{geometry-frames}

为了避免页码与框架冲突,我们需要减少页码footskip(将数字放在框架内)或增加页码(将数字放在框架外)。我首先假设数字应该在框架内,然后使用几何学增加。重要的是\geometryfootskip对布局的任何更改都必须通过几何学否则就会发生奇怪的事情。(使用软件包时总是如此 - 不仅仅是我添加的软件包。)

\geometry{footskip=.2in}

.4in现在我们用文本周围的边距和1.5pt框架的粗线的所需值来设置框架。

\GeometryFrame[.4in][1.5pt]

框架就完成了。现在来设置页码。由于您已经使用了花式高清,这很简单。

\pagestyle{fancy}
\fancyhf{}
\renewcommand\headrulewidth{0pt}
\fancyhf[rf]{\thepage}

我们将框架内的页脚偏移一个等于的值,以\footskip保持或多或少的对称性。

\fancyheadoffset[rf]{.2in}

结果:

框架内带有页码的演示

如果您想要框架外的页码,请对\footskip和设定不同的值\fancyheadoffset。例如,

\geometry{footskip=1.4in}

\fancyheadoffset[rf]{.9in}

生产

框外数字

完整代码

环境filecontents只是为了方便,所以geometry-frames.sty第一次编译代码时会写入。当然,如果geometry-frames.sty你愿意的话,可以直接保存包代码。

\begin{filecontents}{geometry-frames.sty}% package code
\ProvidesPackage{geometry-frames}
\RequirePackage{geometry,etoolbox,xparse,calc}
\newif\ifgeometryframes@frame@page
\geometryframes@frame@pagetrue
\NewDocumentCommand\GeometryFrame { O {5pt} O {.4pt} }
{%
  \setlength\geometryframes@frame@page@margin{#1}%
  \setlength\geometryframes@frame@page@rule{#2}%
  \geometryframes@frame@pagetrue
}
\NewDocumentCommand\NoGeometryFrame {}
{%
  \geometryframes@frame@pagefalse
}
\newlength\geometryframes@frame@page@margin
\newlength\geometryframes@frame@page@rule
\newlength\geometryframes@width
\newlength\geometryframes@height
\newdimen\geometryframes@moveright
\AtBeginDocument{% modified from geometry.sty
  \if@tempswa\relax\else
  \RequirePackage{atbegshi}%
  \AtBeginShipout{\setbox\AtBeginShipoutBox=\vbox{%
      \baselineskip\z@skip\lineskip\z@skip\lineskiplimit\z@
      \Gm@pageframes\box\AtBeginShipoutBox}}%
  \fi
}
\apptocmd\Gm@pageframes{% modified from \Gm@pageframes
 \ifgeometryframes@frame@page
   \setlength\geometryframes@width{\textwidth+2\geometryframes@frame@page@margin}%
   \setlength\geometryframes@height{\textheight+2\geometryframes@frame@page@margin+2\geometryframes@frame@page@rule}%
   \if@twoside
     \ifodd\count\z@
       \let\@themargin\oddsidemargin
     \else
       \let\@themargin\evensidemargin
     \fi
    \fi
    \let\geometryframes@moveright\@themargin
    \advance\geometryframes@moveright by -\geometryframes@frame@page@margin
    \moveright\geometryframes@moveright%
    \vb@xt@\z@{%
     \vskip\topmargin
     \vskip\headheight
     \vskip -\geometryframes@frame@page@margin
     \vskip\headsep\vb@xt@\z@{\vss\geometryframes@hrule}%
     \vskip -\geometryframes@frame@page@rule
     \geometryframes@vrules
     \vb@xt@\z@{\vss\geometryframes@hrule}%
     \vss}%
    \fi%
  }{\typeout{patch applied!}}{\typeout{oh, no!}}%
\newcommand*{\geometryframes@vrules}{% modified from \Gm@vrules@mpi
  \hb@xt@\geometryframes@width{\llap{\geometryframes@vrule}\ignorespaces
  \hskip \geometryframes@width\geometryframes@vrule}}%
\def\geometryframes@vrule{\vrule width \geometryframes@frame@page@rule height\geometryframes@height depth\z@}% modified from \Gm@vrule
\def\geometryframes@hrule{\hrule height \geometryframes@frame@page@rule depth\z@ width\geometryframes@width}% ditto for \Gm@hrule
\end{filecontents}

\documentclass{article}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{background}
\usepackage{graphicx}
\usepackage{geometry-frames}
\geometry{footskip=.2in}
% \geometry{footskip=1.4in}
\GeometryFrame[.4in][1.5pt]
\pagestyle{fancy}
\fancyhf{}
\renewcommand\headrulewidth{0pt}
\fancyhf[rf]{\thepage}
\fancyheadoffset[rf]{.2in}
% \fancyheadoffset[rf]{.9in}
\backgroundsetup{%
  scale=1,
  color=black,
  opacity=1,
  angle=0,
  position=current page.south,
  vshift=1in,
  contents={%
  \small\sffamily
  \begin{minipage}{.18\textwidth}
 \includegraphics[width=\linewidth,height=25pt,keepaspectratio]{cath}%
  \end{minipage}%
  }%
}
\begin{document}
\lipsum
\end{document}

相关内容