Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question

5 Answers 5

up vote 26 down vote accepted

Look, ma! No loops! :)

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

\documentclass{minimal}
\usepackage[a4paper,margin=2mm]{geometry}
\usepackage{graphicx}

\sbox0{%
  \includegraphics{image}%
  \kern2mm
  \vrule width 0pt depth 2mm}

\setlength{\parindent}{0pt}

\begin{document}

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

\end{document}

enter image description here

share|improve this answer
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. :) –  Paulo Cereda 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

\documentclass{article}
\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
\begin{document}
\setlength{\baselineskip}{2cm}%
\newcounter{qrcodesA}\newcounter{qrcodesB}%
\forloop{qrcodesA}{0}{\value{qrcodesA}<12}{% Rows
  \noindent%
  \forloop{qrcodesB}{0}{\value{qrcodesB}<9}{% Columns
    \psbarcode{tex.stackexchange.com}{}{qrcode}\hspace{2cm}}\hspace*{\fill}\\%
  }%
}
\end{document}

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.

share|improve this answer
    
...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.

\documentclass[a4paper]{article}
\usepackage[top=.1cm, left=0.1cm,bottom=.1cm,right=0.1cm]{geometry}
\usepackage{graphicx}
\def\qcode{\includegraphics{./graphics/qrcode}}
\parindent0pt
\pagestyle{empty}
\begin{document}
\newcounter{cnt}
\setcounter{cnt}{0}
\loop
\qcode
\stepcounter{cnt}
\ifnum\thecnt<185
\repeat
\end{document}

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

enter image description here

share|improve this answer

run with xelatex or latex->dvips->ps2pdf

\documentclass{article}
\usepackage{multido,pst-barcode}
\def\xstrut{\rule{0pt}{2cm}}
\parindent=0pt
\pagestyle{empty}
\begin{document}
\multido{\iA=0+1}{54}{% 
  \makebox[2cm]{\xstrut\psbarcode{tex.stackexchange.com}{}{qrcode}} }
\end{document}
share|improve this answer

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):

\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage[showframe]{geometry}
\usepackage{pgf}
\usepackage{pgffor}

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

\newlength{\WidthOfImage}%
\setlength{\WidthOfImage}{2.0cm}%

\newlength{\HeightOfImage}%
\setlength{\HeightOfImage}{2.0cm}%

\pgfmathtruncatemacro{\NumberOfRows}{\textheight/(\HeightOfImage+\Separation)}%
\pgfmathtruncatemacro{\NumberOfColumns}{\textwidth/(\WidthOfImage+\Separation)}%

\begin{document}
%NumberOfRows = \NumberOfRows\par
%NumberOfColumns = \NumberOfColumns\par
%
\foreach \x in {1,...,\NumberOfRows}{\noindent%
    \foreach \y in {1,...,\NumberOfColumns}{%
        \includegraphics[width=\WidthOfImage,height=\HeightOfImage]{image}%
        \hspace{\Separation}%
    }%
    \newline%
}%
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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