1

I am trying to draw a horizontal line using tikz relative to the page top/bottom. Something similar to this, but using a line (simple \draw). What I have so far:

\begin{tikzpicture}[overlay, remember picture]
  \draw[thin, gray, anchor=south] (-11,-20.4) -- (11,-20.4);
\end{tikzpicture}

My goal is to get rid of the absolute coordinates and replace them with i.e. current page.north and an offset of e.g. 2cm, but I wasn't able to figure it out yet. Any hints or tricks are greatly appreciated, thx!

EDIT: (figured it out thx to the input below)

\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)$);

Thx!

tkazik
  • 119

1 Answers1

2

All credits to Milo, since you only have to adapt the code you linked your question to. Then with use of the calc TikZ library, you can adjust the gap you want.

\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}

Without gap:

from corner to corner

With 1 % gap:

with some blank

SebGlav
  • 19,186