边框顶部显示

边框顶部显示

我需要在页面的最顶部显示边框,但我不知道该怎么做。如果 CSS 有帮助,则应为:border-top: 5px solid blue; 在此先感谢您的帮助。

答案1

另一种可能性是使用background包裹。

\documentclass{article}  
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{background}

\usepackage{lipsum}% just to generate text for the example

\backgroundsetup{
scale=1,
angle=0,
contents={
  \tikz[remember picture,overlay]
    \draw [magenta,line width = 5pt] (current page.north west) -- (current page.north east);}
  }

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

在此处输入图片描述

特写:

在此处输入图片描述

\draw [magenta,line width = 5pt]... 您可以在 选项中更改线宽、颜色等角度、缩放比例等\backgroundsetup{...}。有关详细信息,texdoc background请访问www.texdoc.net

答案2

(1:红色边框)您可以使用 TikZ 和绝对页面锚点来绘制边框和everyshi包将其添加到每个页面上。

\EveryShipout{%
   \tikz[remember picture,overlay]
      \draw [draw=red,line width=10pt]% only half of the line will
                                      % be visible on the page
         (current page.north west) -- (current page.north east);
}

(2:蓝色边框)例如,如果您只想在常规文本页面上添加边框,则可以使用页眉来添加线条。以下示例使用scrpage2, 例如:

\chead[]{
   \tikz[remember picture,overlay]
      \draw [blue,line width=10pt]% only half of the line will
                                      % be visible on the page
         (current page.south west) -- (current page.south east);
}

其中空的可选参数导致章节起始页和空白页没有行。

(3:绿色边框)要在章节起始页上添加一行,只能使用 KOMA-Script 中的章节字体(或创建新的章节页眉样式,或使用titlesec):

\addtokomafont{chapter}{%
   \tikz[remember picture,overlay]
      \draw [draw=green,line width=70pt]% only half of the line will
                                      % be visible on the page
         (current page.north west) -- (current page.south west);
}

示例图片

全 MWE展示所有三种方法:

\documentclass{scrbook}

\usepackage{tikz}% for (1) to (3)
\usepackage{everyshi}% only for (1)
\usepackage{scrpage2}% only for (2)
\usepackage{lipsum}% blind text for demonstration

% (1) add the top border at every page
\EveryShipout{%
   \tikz[remember picture,overlay]
      \draw [draw=red,line width=70pt]% only half of the line will
                                      % be visible on the page
         (current page.north west) -- (current page.north east);
}

% (2) add a bottom margin only on regular text pages, i.e. not
% on chapter-start pages or empty pages
\chead[]{
   \tikz[remember picture,overlay]
      \draw [blue,line width=70pt]% only half of the line will
                                      % be visible on the page
         (current page.south west) -- (current page.south east);
}
\pagestyle{scrheadings}

% (3) add a border on chapter-start pages only
\addtokomafont{chapter}{%
   \tikz[remember picture,overlay]
      \draw [draw=green,line width=70pt]% only half of the line will
                                      % be visible on the page
         (current page.north west) -- (current page.south west);
}

\begin{document}
\chapter{First Chapter}
\lipsum[1-12]
\chapter{Second Chapter}
\lipsum
\end{document}

相关内容