TransWikia.com

centered text in sticky labels package

TeX - LaTeX Asked by markgalassi on May 2, 2021

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
? 

2 Answers

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}{}{}
defstart@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

Correct answer by egreg on May 2, 2021

documentclass{article}
usepackage{labels}
usepackage{xpatch,ragged2e}
makeatletter
xpatchcmd{start@@label}{raggedright}{Centering}{}{}
%xpatchcmd{end@@label}{end{minipage}}{parend{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.

Answered by user11232 on May 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP