3

I am currently trying to create a label sheet with different bar codes on them.

This is how far I got:

\documentclass[12pt,a4paper]{article}
\usepackage[newdimens]{labels}

%% Change variables here:
\newcommand{\barprefix}{XX}
\newcommand{\barversion}{00}
\newcommand{\baryear}{2017}
\newcommand{\barmonth}{04}
\newcommand{\barstartid}{10}

\newcommand{\bartype}{code128}

% Label format:
\LabelCols=3
\LabelRows=8
\LeftPageMargin=7mm
\RightPageMargin=7mm
\TopPageMargin=15mm
\BottomPageMargin=15mm
\InterLabelColumn=2mm
\InterLabelRow=0mm
\LeftLabelBorder=5mm
\RightLabelBorder=5mm
\TopLabelBorder=5mm
\BottomLabelBorder=5mm
\numberoflabels=\LabelCols

\usepackage{pst-barcode}

\usepackage{pgf}
\usepackage{pgffor}

\begin{document}
    \pgfmathparse{subtract(\LabelRows,1)}%
    \pgfmathint{\pgfmathresult}%
    \foreach \n in {0,...,\pgfmathresult}{%
        \pgfmathsetbasenumberlength{3}%
        \pgfmathparse{add(\n,\barstartid)}%
        \pgfmathint{\pgfmathresult}%
        \pgfmathdectobase\barid{\pgfmathresult}{10}%
        \genericlabel{%
            \fbox{%
                \begin{pspicture}(0,-0.2)(4.8,1)%
                    \psbarcode{\barprefix\barversion\baryear\barmonth\barid}{includetext includecheck includecheckintext height=0.4}{\bartype}%
                \end{pspicture}%
            }%
        }%
    }
\end{document}

The problem with this code is that instead of printing all the labels on one page, it creates a separate page for each row of labels. I can solve this if I just remove the foreach loop and enter every label row via genericlabels myself, but I would like to do this with a for loop so that I just need to change the rows parameter.

Thanks for your help.

  • Welcome to TeX.SX! – Heiko Oberdiek Apr 3 '17 at 16:39
  • \foreach adds grouping, you can use \pgfplotsforeachungrouped from the pgfplots package instead. Or some other loop command (e.g. \int_step_variable:nnnNn {0} {1}{\pgfmathresult}{\n} from expl3 works fine too). – Ulrike Fischer Apr 3 '17 at 16:51
  • Thanks @UlrikeFischer that did it!You might want to write an answer for it, so I can vote. – cmhe Apr 3 '17 at 17:03
3

\foreach adds grouping. You can use \pgfplotsforeachungrouped from the pgfplots package instead. Or some other loop command (e.g. \int_step_variable:nnnNn {0} {1}{\pgfmathresult}{\n}{...} from expl3 works fine too).

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.