我正在尝试打印一堆标签并使用 LaTeXlabels.sty
样式记录在http://tug.ctan.org/macros/latex/contrib/labels/labels.pdf
这些不是用于街道地址(自然是左对齐),而是放在国际象棋奖杯上(我发现了金箔标签)。
不幸的是,我不知道如何让文本居中,而左对齐对于奖杯标签来说效果不太好。文档似乎没有解决这个问题。
在labels.sty
源代码中,我看到第 219 行以以下内容开始表格环境:
\settoheight{\LabTmp}%
{\begin{tabular}{l}\usebox{\this@label}\end{tabular}}%
但如果我将其更改{l}
为,{c}
结果就不一致,而且不是我真正想要的,就好像只有一条线居中一样。
有人知道这是否可以做到吗?或者我是否可以在标签数据文件中放入一些特殊控制字符来稍微调整间距?
[编辑:添加 MWE;Peter,谢谢你指出这一点]
[注意:目前提供的两种解决方案都很好,但与我的 MWE 合并存在问题:我使用 \TopPageMargin 和 \BottomPageMargin 来调整打印机的偏移量,如果我使用 xpatch 方法,这些宏就会失败]
这是文件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}
这是一个小标签文件 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
由此我得到:
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
?
答案1
默认情况下,标签排版为右侧不规则,行尾表示\newline
。因此,仅使用\centering
而不是\raggedright
是不够的,我们需要\par
在行结束时发出。
\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}
答案2
\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}
您将收到坏盒子,我希望您能忍受它。