6

I know this is probably one of the weirdest requests on this forum, but I am just not getting anywhere on my own. I use latex to write my worksheets for my students. I often use the margins for tips and hints or small graphics. Unfortunately, the problem arises that the students obviously often want to print the sheets and then the hole punch holes hit those little graphics. I would like to get around that. Is there any chance to define a tikz picture or something else, which depicts the two hole punch holes on all pages while I write on the worksheets to place the margins entries appropriately?

I literally have no idea on how to even get started.

Nadine
  • 279
  • 4
  • 7
  • Did you try this already? https://tex.stackexchange.com/questions/455307/how-to-draw-punch-holes-in-the-margins – SebGlav Mar 21 '21 at 20:05
  • We had something like this a while back: https://tex.stackexchange.com/questions/582752/making-tikz-shapes-surfaces-that-dont-appear-in-the-pdf/582767#582767 – DG' Mar 21 '21 at 20:06
  • https://tex.stackexchange.com/questions/121393 – Dr. Manuel Kuehner Mar 21 '21 at 20:06
  • 1
    The location of the punch holes is not unique. It depends on the page dimensions, and on whether the one adding the holes uses the right settings. –  Mar 21 '21 at 20:07

2 Answers2

10

\documentclass[]{article}
\usepackage{tikz}
\usepackage{blindtext}
\usepackage{atbegshi} % https://www.ctan.org/pkg/atbegshi

\newcommand\myPunchHole{% \begin{tikzpicture}[remember picture,overlay] \draw (current page.west) node[circle, minimum size=5mm, draw, xshift = 6mm, yshift = 30mm]{}; \draw (current page.west) node[circle, minimum size=5mm, draw, xshift = 6mm, yshift = -30mm]{}; \end{tikzpicture}% }

\AtBeginShipout{\myPunchHole} \AtBeginShipoutFirst{\myPunchHole}

\begin{document}

\blindtext[6]

\end{document}

enter image description here


Related

4

You can avoid atbegshi using the \AddToHook command. Here is a MWE, taking the tikz code by Dr. Manuel Kuehner. The output is the same:

\documentclass{article}
\usepackage{tikz}
\usepackage{blindtext}

\AddToHook{shipout/background}{% \begin{tikzpicture}[overlay,remember picture,every node/.style={circle, minimum height=5mm,minimum width=5mm,draw, xshift = 6mm}] \draw (current page.west) node[yshift = 30mm]{}; \draw (current page.west) node[yshift = -30mm]{}; \end{tikzpicture}% }

\begin{document}

\blindtext[6]

\end{document}

EDIT

SebGlav's observation is quite right. In a two-sided document, holes cannot be placed on the left on every page, but left on odd pages and right on even pages. There are two solutions: 1) leave the even pages blank; 2) draw the holes on the right in the even pages

Solution 1) Holes only on odd pages:

\AddToHook{shipout/background}{%
 \ifodd\value{page}
 \begin{tikzpicture}[overlay,remember picture,every node/.style={circle, minimum height=5mm,minimum width=5mm,draw, xshift = 6mm}]
 \draw (current page.west) node[yshift = 30mm]{};
 \draw (current page.west) node[yshift = -30mm]{};
 \end{tikzpicture}%
 \fi
}

Solution 2) Holes on the left and right, respectively, in the odd and even pages:

\AddToHook{shipout/background}{%
 \ifodd\value{page}
 \begin{tikzpicture}[overlay,remember picture,every node/.style={circle, minimum height=5mm,minimum width=5mm,draw, xshift = 6mm}]
 \draw (current page.west) node[yshift = 30mm]{};
 \draw (current page.west) node[yshift = -30mm]{};
 \end{tikzpicture}%
 \else
 \begin{tikzpicture}[overlay,remember picture,every node/.style={circle, minimum height=5mm,minimum width=5mm,draw, xshift = -6mm}]
 \draw (current page.east) node[yshift = 30mm]{};
 \draw (current page.east) node[yshift = -30mm]{};
 \end{tikzpicture}%
 \fi
}

Solution 2bis) Like above, but saving a few lines of code:

\newcommand{\printholes}[2]{%
 \begin{tikzpicture}[overlay,remember picture,every node/.style={circle, minimum height=5mm,minimum width=5mm,draw, xshift = #1}]
 \draw (current page.#2) node[yshift = 30mm]{};
 \draw (current page.#2) node[yshift = -30mm]{};
 \end{tikzpicture}%
}
\AddToHook{shipout/background}{%
 \ifodd\value{page}
   \printholes{6mm}{west}
    \else
   \printholes{-6mm}{east}
 \fi
}
Ivan
  • 4,368
  • 1
    Very nice and customizable. And if one has to print 2-sided documents? – SebGlav Mar 21 '21 at 20:25
  • 2
    @SebGlav Maybe one can use this http://www.texfaq.org/FAQ-oddpage within the \AddToHook. Or see https://tex.stackexchange.com/questions/154256 (\ifodd\value{page}). – Dr. Manuel Kuehner Mar 21 '21 at 22:23
  • 1
    @SebGlav Thanks for the suggestion. You are right. I did not think about it, I edited the answer. – Ivan Mar 21 '21 at 23:12
  • I am unable to have this compile. ... Undefined control sequence \AddToHook{...}. TexLive 2020 with pdfTeX. – Jeffrey J Weimer Mar 21 '21 at 23:24
  • Is your TeX Live distribution updated? – Ivan Mar 21 '21 at 23:52
  • @Ivan that is perfect! Thank you so much! It took me a while to find a solution to "undefined control sequence \AddToHook" as well @SebGlav! Had to update the TeX Live distribution as Ivan mentioned above. Now it works wonderfully! Again, thank you so much for your kind help guys! – Nadine Mar 22 '21 at 05:47
  • OK. Updated TeXLive. It now works. As with the approach from @Dr.ManuelKuehner, this needs two compilations to print the marks. Thank you! – Jeffrey J Weimer Mar 22 '21 at 21:05