How can I create exactly sized labels with centered text (horizontally and vertically) for my doorbell and letterbox with LaTeX? The labels need to have borders, so I can cut them after printing and the dimensions need to be exact in order to fitting into the spaces available.
3 Answers
With some more options to set but very exact width and height, if needed:
The width
and height
options 'guarantee' that the width including the rulers are used, not the text area. (This depends on the chosen font size of course -- if the size is too large, the restrictions won't apply of course)
Choose the left
etc. options at will.
\documentclass{article}
\usepackage[most]{tcolorbox}
\newtcolorbox{cenbox}[1][]{enhanced,
%nobeforeafter, %only needed if more labels should be printed on a special paper with self-adhesive labels
sharp corners,
valign=center,
halign=center,
boxrule=1pt,
boxsep=0pt,
colback=white,
colframe=black,
left=2pt,
top=2pt,
right=2pt,
bottom=2pt,
#1
}
\begin{document}
\begin{cenbox}[width=5cm,height=2cm]
Mr. Arthur Gumby
Brain Specialist
\end{cenbox}
\end{document}
If some other kind of labels should be generated, please have a look on ab old question of mine: Unwanted vertical separation between tcolorboxes
-
Seems to be the better solution, but I'll have to wait for internet access in our new home first in order to installing the missing package.– RBloethSep 4, 2016 at 9:21
Would a simple fbox
around a minipage
do the job?
\documentclass{article}
\setlength{\fboxsep}{-\fboxrule}
\begin{document}
\fbox{%
\begin{minipage}[t][2cm][c]{\dimexpr5cm-2\fboxrule}
\centering
My Name
City
\end{minipage}%
}
\end{document}
-
1
-
@Bernard Thanks a lot for this suggestion! I edited my answer. Sep 3, 2016 at 18:59
-
Unfortunately when I print my labels like this, the widths don't match my attributes but are smaller... I'll try the other solution now.– RBloethSep 4, 2016 at 9:19
-
@RBloeth: Actually, for me the labels are somewhat larger, because there is a spurious space and the width of frame is miscalculated!– user31729Sep 4, 2016 at 9:57
-
@samcarter: Please try
\begin{minipage}[t][2cm][c]{\dimexpr5cm-2\fboxrule}
and add a%
after\fbox{%
and after\end{minipage}
-- after that changes the width has the desired width for me!– user31729Sep 4, 2016 at 9:59
A plain TeX approach:
\vbox{\hrule
\hbox to 55mm{\vrule\hss
\vbox to 34mm{\vss\halign{\hfil#\hfil\cr
Arthur Gumby M.D.\cr
Brain Surgeon\cr
}\vss}\hss\vrule}\hrule}
\bye
-
My brain hurts because my line was stolen ... ;-)– user31729Sep 4, 2016 at 23:18
-
-
Thanks for the answer, but also this doesn't work for me. I get neither the height nor the width defined in your example. Possibly because I use a DIN A4 paper size?– RBloethOct 16, 2016 at 11:43
\documentclass[a4paper,12pt]{article} \usepackage[utf8]{inputenc} \usepackage[ngerman]{babel}
and I use TeXworks under Ubuntu.