5

I'm trying to print a bunch of labels and using the LaTeX labels.sty style documented at http://tug.ctan.org/macros/latex/contrib/labels/labels.pdf

These are not for street addresses (which are naturally left-justified), but rather to put on chess trophies (I found gold leaf labels).

Unfortunately I cannot figure out how to make the text centered, and left-justified does not work so well for a trophy label. The documentation does not seem to address it.

In the labels.sty source I see that line 219 begins a tabular environment with:

 \settoheight{\LabTmp}%
  {\begin{tabular}{l}\usebox{\this@label}\end{tabular}}%

but if I change the {l} to {c} the results are inconsistent and not really what I want, almost as if only one of the lines was centered.

Does anyone know if that can be done? Or if I can put some special control characters in the label data file to nudge the spacing a bit?

[EDIT: adding MWE; Peter, thanks for pointing that out]

[note: the two solutions offered so far are very good, but merging with my MWE is a problem: I use \TopPageMargin and \BottomPageMargin to adjust to my printer's offsets and those macros fail if I use the xpatch approach]

Here is the file labels-trophies.tex:

\documentclass[12pt,letterpaper]{article}
\usepackage[newdimens]{labels}
\LabelInfotrue
\TopPageMargin=16mm
\BottomPageMargin=12mm
\begin{document}
\LARGE
\LabelRows=10
\LabelCols=2
\labelfile{trophies-mwe.dat}
\end{document}

and here is a small label file trophies-mwe.dat:

NM K-9 Championship
2014 State Champion

NM K-9 Championship
2014 State Co-Champion

NM K-6 Championship
2014 State Champion

NM K-6 Championship
2014 State Co-Champion

NM K-3 Championship
2014 State Champion

NM K-3 Championship
2014 State Co-Champion

From this I get:

markgalassi@mozart:~/h/misc/chess/state-champs/2015$ pdflatex labels-trophies-centered.tex 
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2015/dev/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./labels-trophies-centered.tex
LaTeX2e <2014/05/01>
Babel <3.9l> and hyphenation patterns for 2 languages loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/labels/labels.sty)
! Undefined control sequence.
l.4 \TopPageMargin
                  =16mm
? 
  • Welcome to TeX.SE. It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem.

    While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem.

    – Peter Grill Mar 09 '15 at 06:51

2 Answers2

5

By default, the labels are typeset ragged right and the end of line means \newline. So just using \centering instead of \raggedright is not sufficient and we need to issue \par when a line ends.

\documentclass{article}
\usepackage{labels}
\usepackage{xpatch}
\makeatletter
\xpatchcmd{\start@@label}{\raggedright}{\centering}{}{}
\def\start@newline{\par}%
\makeatother

\begin{document}
\begin{labels}
Me
My address
My City, State, Zipcode

My Brother
His address
His City, State, Zipcode

You
Your address
Your City, State, Zipcode
\end{labels}

\end{document}

enter image description here

egreg
  • 1,121,712
  • egreg, thank you so much for your solution. it works very well, but seems to have side-effects. I have now edited to add an MWE and my setting of margins fails when I use your xpatch approach. any chance you could take another peek? grazie tanto! – markgalassi Mar 11 '15 at 03:24
  • @markgalassi I get Label too tall by 2mm (5.03885pt) with or without the patch. – egreg Mar 11 '15 at 07:58
  • I wish that was what I got; I'm getting: "Undefined control sequence l.4 \TopPageMargin=16mm" (see further edit for full error message) – markgalassi Mar 11 '15 at 13:29
  • @markgalassi That's quite strange: what version of labels.sty do you have? On my system it is v.13, released 2003/05/22 (the information is in the .log file). – egreg Mar 11 '15 at 14:06
  • the one I have in debian unstable is the same as yours: 2003/05/22 v.13. – markgalassi Mar 11 '15 at 17:51
  • I have placed the full log file (and full .tex and .dat files) at [link] http://www.galassi.org/mark/share-files/.stackexchange/ – markgalassi Mar 11 '15 at 18:17
  • @markgalassi You have to use the newdimens option to labels: \usepackage[newdimens]{labels}. – egreg Mar 11 '15 at 18:50
4
\documentclass{article}
\usepackage{labels}
\usepackage{xpatch,ragged2e}
\makeatletter
\xpatchcmd{\start@@label}{\raggedright}{\Centering}{}{}
%\xpatchcmd{\end@@label}{\end{minipage}}{\par\end{minipage}}{}{}
\makeatother
\begin{document}
\begin{labels}
Me
My address
My City, State, Zipcode
My Brother
His address
His City, State, Zipcode
\end{labels}

\end{document}

enter image description here

You will get badboxes, I hope you can live with it.