我正在尝试使用 tikz 绘制一条相对于页面顶部/底部的水平线。类似于这,但使用一条线(简单\draw
)。到目前为止,我拥有:
\begin{tikzpicture}[overlay, remember picture]
\draw[thin, gray, anchor=south] (-11,-20.4) -- (11,-20.4);
\end{tikzpicture}
我的目标是摆脱绝对坐标,用 iecurrent page.north
和偏移量 eg代替它们2cm
,但我还没能弄清楚。任何提示或技巧都非常感谢,谢谢!
编辑:(根据下面的输入弄清楚了)
\newcommand\mOffset{2.8} % margin offset of vertical bar from top/bottom [cm]
% top bar
\draw[thin, gray] ($(current page.north west)+(0,-\mOffset)$) -- ($(current page.north east)+(0,-\mOffset)$);
% bottom bar
\draw[thin, gray] ($(current page.south west)+(0,\mOffset)$) -- ($(current page.south east)+(0,\mOffset)$);
谢谢!
答案1
所有功劳都归功于 Milo,因为你只需要调整你链接到问题的代码。然后使用calc
Ti钾Z库,你可以调整你想要的间隙。
\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage{blindtext}
\usepackage{atbegshi}
\usetikzlibrary{calc}
\newcommand\diagline{%
\begin{tikzpicture}[remember picture,overlay]
% from one corner to the other
%\draw [remember picture,overlay,blue] (current page.south west) -- (current page.north east);
%With a gap of 1%
\draw [remember picture,overlay,blue] ($(current page.south west)!0.05!(current page.north east)$) -- ($(current page.south west)!0.95!(current page.north east)$);
\end{tikzpicture}%
}
\pagestyle{empty}
\AtBeginShipout{\diagline}
\AtBeginShipoutFirst{\diagline}
\begin{document}
\blindtext[6]
\end{document}
无间隙:
差距为 1%: