I want to print a A4 paper full of the same QR image. I want more elegant way to this answer here, yes I can get it working like that but I want to leave just enough space for scissors and no space near the edges and equal spacing (and is it possible to do that with for -loop or otherwise simpler?) -- possible?

enter image description here


Look, ma! No loops! :)

Borrowed from the TeXbook, exercise 21.8 (p. 225).


  \vrule width 0pt depth 2mm}



\cleaders\hbox to\textwidth{\leaders\copy0\hfill}\vfill


enter image description here

  • 5
    I need to learn to save votes for moments like this one. :) A tear of joy fell from my eye. A true capolavoro! I wish I could vote it 10 times. :) Jan 16 '12 at 23:44
  • @PauloCereda Just DEK's code adapted to the situation.
    – egreg
    Jan 16 '12 at 23:49
  • 1
    Your image has white space around it. Try putting it into an \fbox to see how much. With the macros I proposed, there are exactly 2mm between images.
    – egreg
    Jan 17 '12 at 0:34
  • 2
    @hhh GIF files are not supported by TeX programs. Convert it to PNG.
    – egreg
    Jan 17 '12 at 21:36
  • 2
    @hhh Probably the image is too big. Check its dimensions with the \fbox method I mentioned.
    – egreg
    Jan 17 '12 at 21:49

Here is one way using the forloop package which implements an elementary nested/recursive for loop using counters. Given some counter <cnt>, the interface

\forloop[<step>]{<cnt>}{<start>}{<condition>}{<loop content>}

initializes <cnt> to <start> and executes <loop content> until <condition> is met. An optional first parameter <step> (default is 1) can be set to modify the counter step size:

enter image description here

\usepackage[margin=2cm,a4paper]{geometry}% http://ctan.org/pkg/geometry
\usepackage{forloop}% http://ctan.org/pkg/forloop
\usepackage{pst-barcode}% http://ctan.org/pkg/pst-barcode
\pagestyle{empty}% No page headers/footers
\forloop{qrcodesA}{0}{\value{qrcodesA}<12}{% Rows
  \forloop{qrcodesB}{0}{\value{qrcodesB}<9}{% Columns

Using \psbarcode directly creates a dimensionless object (width and height of 0pt). The spacing of 2cm is arbitrary, as is the setting for \baselineskip. You can modify this to suit your scissor-cutting expertise.

This requires a latex->dvips->ps2pdf or xelatex compilation sequence.

  • ...this covers the corners/sides apparently +1.
    – hhh
    Jan 17 '12 at 0:33
  • @hhh: You can modify the row and column counters, as well as the margins set by geometry. I chose margin=1cm, but you can reduce that to your liking as long as your printer can handle it. Is that what you're referring to by "covering the corners/sides"?
    – Werner
    Jan 17 '12 at 1:09
  • there is no "includegraphics"? This is nice! It generates the images directly from the text! (needless to have middle image) Is it possible to output the ps to image formats such as png?
    – hhh
    Jan 17 '12 at 21:08
  • 1
    @hhh: The picture is generated by LaTeX via the package pst-barcode. It has a function (or command) \psbarcode{...}{}{qrcode} which generates the output since the structure for producing QR codes is known. The benefit of producing it on-the-fly means that you can literally create your own QR code for every image that you produce, rather than have them all the same. My code produces the exact same QR code, pointing to TeX.SX. Yes, you can port the output to an image form.
    – Werner
    Jan 17 '12 at 21:14
  • @hhh: You won't be able to output directly to PNG, but you can output to PS or PDF and convert to PNG. Also, this holds for either the entire page (as in my example), or a single QR code.
    – Werner
    Jan 17 '12 at 21:16

You can loop using Knuth's \loop and \repeat. Here some minimal code. You will need to experiment with the gutter between the images, as well as the numbers and scaling of the image.

\usepackage[top=.1cm, left=0.1cm,bottom=.1cm,right=0.1cm]{geometry}

Here is the result. You can also print the qrcode with LaTeX using pstricks.

enter image description here


run with xelatex or latex->dvips->ps2pdf

  \makebox[2cm]{\xstrut\psbarcode{tex.stackexchange.com}{}{qrcode}} }

One way would be to compute the number that can fit on one line based on the \WidthOfImage, and the number of rows based on the \HeightOfImage (adjusting for the spacing required by the scissors):



\setlength{\Separation}{0.1cm}% Space for the "scissors"




%NumberOfRows = \NumberOfRows\par
%NumberOfColumns = \NumberOfColumns\par
\foreach \x in {1,...,\NumberOfRows}{\noindent%
    \foreach \y in {1,...,\NumberOfColumns}{%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.