Which LaTeX Package Generates QR Codes?
At a glance
- 1. Load the package
Add qrcode to the document preamble with the usepackage command.
- 2. Enter the payload
Place the text or URL you want encoded inside the qrcode command.
- 3. Set the printed size
Use the height option to choose the QR code's physical height.
- 4. Compile and test
Build the PDF, scan the code, and leave clear space around it.
The qrcode package is a straightforward way to put a QR code directly into a LaTeX document. You provide the text or URL to encode, and the package generates the code when you compile the document.
Use the qrcode package
Load the package in the preamble and use its \qrcode command where you want the code to appear. Here is a complete example you can compile:
\documentclass{article}
\usepackage{qrcode}
\begin{document}
Scan this code to visit the project page:
\begin{center}
\qrcode[height=3cm]{https://example.com/project}
\end{center}
\end{document}
The height option sets the printed height. Replace the example URL with the exact content you want the scanner to read. You can put ordinary text in the braces as well as a URL.
The package is called qrcode on CTAN. If LaTeX reports that qrcode.sty is missing, install the package through your TeX distribution’s package manager, or install it through the package manager used by your online editor.
Adjusting size and error correction
The optional argument controls settings, while the required argument is the payload—the text or URL encoded into the pattern. For instance:
\qrcode[height=4cm,level=H]{https://example.com/project}
The level option selects an error-correction level: L, M, Q, or H. Higher error correction can make a code more resilient to damage or obstruction, but it reduces how much data fits in a given QR version. If you do not need to control the level, start with the package defaults and test the result.
A QR code’s physical size and its data density are different things. Increasing height makes the printed pattern larger; it does not make the pattern less dense. If the encoded text is long, the QR code may contain more small modules, so print it large enough for the intended scanning distance.
Worked example: encode a short message
To encode a short message instead of a link, change only the required argument:
\qrcode[height=2.5cm]{Meet at the library at 3 pm}
When you compile the document, the printed QR code contains that message. A phone’s camera or QR-reading app can display it without opening a website. To encode a web address, use the full URL, including https://, so scanners recognize it as a link.
Common mistakes
- Leaving out the package: Put
\usepackage{qrcode}before\begin{document}. The command will be undefined if the package is not loaded. - Putting the wrong content in the braces: The content between braces is what the QR code encodes. Check it for typos and test the final PDF by scanning it.
- Using LaTeX-special characters unescaped: Characters such as
%,&,#, and_can be interpreted by LaTeX rather than passed as ordinary payload text. Escape them as needed—for example, write\%for a percent sign—or choose a simpler payload. - Cropping the quiet zone: QR codes need clear space around the pattern to scan reliably. Do not crop close to its edges, and keep nearby text, rules, or graphics out of that margin.
- Printing it too small: A code that looks fine on screen may be hard to scan after printing. Test a physical copy at the size and on the material you plan to use, especially if it will be viewed from a distance.
For documents where the QR code must match a particular branding or production workflow, generate and test the final printed version rather than relying on appearance in the LaTeX preview alone.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.