Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to make sticky labels with LaTeX. I thought this would be pretty simple because of LaTeX's nice support of absolute units, but it turned out to be quite difficult. This is the specification of the label paper:

  • Left and right margin: 0mm
  • Upper and lower margin: 8mm
  • Label height: 25mm
  • Label width: 52mm
  • Inner label margin: 2mm

That's 11 rows and 4 columns of labels. The label will contain just text. Here's what I've got to so far:

\documentclass[portrait,a4paper,danish,oneside,final,10pt]{memoir}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{geometry}
\usepackage{palatino}
\usepackage{tabularx}

\geometry{hoffset=0mm,
          hmargin=0mm,
          vmargin=8mm,
          footskip=0mm,
          papersize={210mm,297mm},
          total={210mm,297mm}}

\pagestyle{empty}
\aliaspagestyle{chapter}{empty}
\aliaspagestyle{part}{empty}

\setlength{\tabcolsep}{2mm}

\newcommand{\labeltext}{\textbf{M\&M} er en sød vin lavet på hyben plukket ved Vemmingbund Strand i Sønderjylland. Vinen produceres.}

\begin{document}\noindent
\begin{tabularx}{\textwidth}{X|X|X|X}\hline
\labeltext & \labeltext & \labeltext & \labeltext \vfill \\%[\mylabelheight]
\labeltext & \labeltext & \labeltext & \labeltext \vfill \\%[\mylabelheight]
\labeltext & \labeltext & \labeltext & \labeltext \vfill \\%[\mylabelheight]
\labeltext & \labeltext & \labeltext & \labeltext \vfill \\%[\mylabelheight]
\labeltext & \labeltext & \labeltext & \labeltext \vfill \\%[\mylabelheight]
\labeltext & \labeltext & \labeltext & \labeltext \vfill \\%[\mylabelheight]
\labeltext & \labeltext & \labeltext & \labeltext \vfill \\%[\mylabelheight]
\labeltext & \labeltext & \labeltext & \labeltext \vfill \\%[\mylabelheight]
\labeltext & \labeltext & \labeltext & \labeltext \vfill \\%[\mylabelheight]
\labeltext & \labeltext & \labeltext & \labeltext \vfill \\%[\mylabelheight]
\labeltext & \labeltext & \labeltext & \labeltext \vfill \\%[\mylabelheight]
\hline
\end{tabularx}%
\end{document}

This is almost correct. However, the table cells don't expand their height to fit the paper (this is, bottom row should touch the bottom margin).

Also, I can't figure out how to get an upper and lower margin of 2mm inside each cell. I tried using \vspace{2mm}, but that produces a much larger space than requested.

I tried posting a picture of the result, but I'm not allowed to at the moment. Sorry.

Thanks in advance!

share|improve this question
1  
You can include the image with the button; just remove the ! in front of the string you get (![text][1]). A user with enough rep will put back the ! for you. You should also have a look at the labels package. –  egreg Sep 24 '12 at 21:46
1  
I heartily second @egreg 's suggestion: take a look at the labels package. –  Brent.Longborough Sep 24 '12 at 22:08
    
@egreg: I'll do that next time, thanks! I looked at the labels package, but from what I understood from the manual, it only works for ond brand of labels (unless I modified the code itself, which I didn't have the courage to do). –  Dan Sep 25 '12 at 7:56
add comment

1 Answer

up vote 5 down vote accepted

Don't take this too seriously. But, hey, it works!

Idea borrowed (or stolen?) from the TeXbook, Exercise 21.8.

\documentclass[a4paper]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[danish]{babel}
\usepackage{geometry}
\usepackage{palatino,microtype}

\geometry{margin=0mm}

\pagestyle{empty}

\newcommand{\labeltext}{%
  \textbf{M\&M} er en sød vin lavet på hyben plukket ved Vemmingbund
  Strand i Sønderjylland. Vinen produceres.}

\fboxrule=0.2pt
\fboxsep=-\fboxrule
\parindent=0pt

\newsavebox{\danbox} 

\begin{document}
\sbox\danbox{%
  \fbox{%
    \vbox to 25mm{
      \hsize=52mm \leftskip=2mm \rightskip=2mm
      \vfill\labeltext\vfill
    }%
  }%
}

\hbox to\hsize{\cleaders\vbox to \vsize{\cleaders\copy\danbox\vfil}\hfil}

\end{document}

enter image description here

The idea is to repeat a box as many times as needed. First of all we build it (with low level commands, in order to have maximum control) and store it in a save bin; by setting \fboxsep to -\fboxrule we ensure that the frame will not add to the height and width of the box. The box itself has a width of 52mm and a height of 25mm (the \vfill at the end will avoid any additional depth due to characters with descenders, as there's no text at the bottom, but glue).

Now the fun begins.

  1. With \hbox to \hsize we tell TeX to build a box as wide as the page.

  2. \cleaders<material>\hfill will fill the width with copies of <material>, pushing them close to each other and adding space to both sides to finish the filling.

  3. Our <material> will be exactly 52mm wide, so four columns, with 1mm of white space on both sides (A4 paper is 210mm wide).

  4. Now we specify the <material>: it's a \vbox to \vsize{...} so it will fill all the page height.

  5. For filling it we do exactly the same: \cleaders\copy\danbox\vfil (we must use \copy rather than \usebox that would start horizontal mode). A4 paper is 297mm high, so eleven rows will be accommodated, leaving 11mm on both ends.

That's it. :)

share|improve this answer
    
Now it's me who is glad of still having one vote left. –  Gonzalo Medina Sep 24 '12 at 22:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.