12

How to draw a crosshair (with specific colour, and line width and height) in the middle of a every page (centered vertically and horizontally). Its position should not affect or be affected by other graphics and text in the page.

This is what I tried so far

\documentclass[10pt,a4paper]{article}
\begin{document}
These 2 lines are centered vertically and horizontally on a page
\hspace{0pt}
\vfill
\begin{center}
\rule{.4\textwidth}{2pt} I \rule{.4\textwidth}{2pt}
  \end{center}
\vfill
\hspace{0pt}
\end{document}
Martin Scharrer
  • 262,582
Hany
  • 4,709

3 Answers3

17

You can use eso-pic to place content in the ForeGround in the centre of every page:

enter image description here

\documentclass{article}

\usepackage{eso-pic,xcolor,lipsum}

\AddToShipoutPictureFG{%
  \AtPageCenter{%
    \color{red}%
    \makebox[0pt]{\rule{250pt}{2pt}}%
    \makebox[0pt]{\rule[-250pt]{2pt}{500pt}}%
  }%
}

\begin{document}

\lipsum[1-50]

\end{document}
Werner
  • 603,163
15

This uses TikZ and places a cross hair at the page center, extending some size to the top/bottom and left/right margins, the dimensions of this is used from the 1st and 2nd arguments of the macro \crosshair. The 3rd argument is meant for colour etc. settings.

Please compile twice to get the node anchor placement correctly.

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{calc}

\usepackage{blindtext}

\newcommand{\crosshair}[3]{%
\begin{tikzpicture}[remember picture,overlay,opacity=0.2]
  \draw[black, line width=2pt,#3] ($(current page.center)-(#1,0)$) -- ($(current page.center)+(#1,0)$);
  \draw[black, line width=2pt,#3] ($(current page.center)-(0,#2)$) -- ($(current page.center)+(0,#2)$);
\end{tikzpicture}%
}

\begin{document}
\crosshair{5cm}{10cm}{blue}
\blindtext[10]
\crosshair{10cm}{2cm}{red,dashed}
\end{document}

enter image description here

Update for crosshairs on every page with everypage package

Use the \AddEverypageHook macro in order to add some code that should be used on every page, i.e. place the \crosshair macro inside \AddEverypageHook as has been done in the code below.

\documentclass{article}

\usepackage{everypage}
\usepackage{tikz}

\usetikzlibrary{calc}

\usepackage{blindtext}

\newcommand{\crosshair}[4][opacity=0.2]{%
\begin{tikzpicture}[remember picture,overlay,#1]
  \draw[black, line width=2pt,#4] ($(current page.center)-(#2,0)$) -- ($(current page.center)+(#2,0)$);
  \draw[black, line width=2pt,#4] ($(current page.center)-(0,#3)$) -- ($(current page.center)+(0,#3)$);
\end{tikzpicture}%
}

\AddEverypageHook{\crosshair[opacity=0.5]{5cm}{10cm}{blue}}

\begin{document}
\blindtext[10]
\end{document}
3

You can use also \watermark or \leftwatermark and \rightwatermark for even/odd pages, or \thiswatermark for a particular page:

mwe

\documentclass{article}
\usepackage{watermark,xcolor}
\usepackage{lipsum} % dummy text
\begin{document}
\thiswatermark{\color{red!50}\rule{.5\textwidth}{0pt}%
\rule[\dimexpr-1\textheight-\headsep]{1pt}{1\textheight}}
\lipsum[1-6]
\end{document}
Fran
  • 80,769