5

The following code produces address labels.

What I am trying to achieve is to fit text to the size of the box created by labels package, this solves the problem with the address is big and overflows the box.

Any pointers to this:

\documentclass[12,a4paper]{article}
\usepackage[no-math]{fontspec}
\setmainfont{DejaVuSans-Bold.ttf}
\usepackage{labels}
\LabelCols=3
\LabelRows=7
\LeftBorder=8mm
\RightBorder=4mm
\TopBorder=14mm
\BottomBorder=11mm
\LabelGridtrue
\LabelInfotrue
\begin{document}
\begin{labels}
\input{Address.dat}
\end{labels}
\end{document}

Contents of Address.dat

E3
XX XXsfdsf 
23,fds sdkfjhdsfkj
fkdfjdskfjh s kjdsf
sdfds sfsdf 4564856

E4 %Bigger adress
sdfsdf dfsdfsd, sdfdsf, sdfsdfs sdfsdfsd dfsd
sdfsfdsfsd sdflkjsdf, sdfsdjldasdsdskdflsd  fasdfdsf
asdsd dfgrettwe 5223502 sdfsdfsdf asdGGHkdsjfhkkjSJGHjg 
sdfdsfsd fdsfsdsdfweweqw weeqweqw


E5
rtretertert rtwer
plpokpqlkdlkpo 
lklkllsdkfjwlek 6787686986

E6
rtretertert rtwer
plpokpqlkdlkpo 
lklkllsdkfjwlek 6787686986

Output

Output

1 Answer 1

1

Here's a manual approach. I also deleted irrelevant (regarding the problem) code.

\documentclass{article}

% Provides \scalebox
\usepackage{graphicx}

% Provided by the OP
\usepackage{labels}
\LabelCols=3
\LabelRows=7
\LeftBorder=8mm
\RightBorder=4mm
\TopBorder=14mm
\BottomBorder=11mm
\LabelGridtrue
\LabelInfotrue

\newcommand{\mySampleText}{Text Text Text Text Text Text Text Text Text Text Text Text }

\begin{document}
% ----- Start of Labels -----
\begin{labels}

% Label 1
    \textbf{Label 1}
    \mySampleText
    \mySampleText
    \mySampleText


% Label 2
    \textbf{Label 2}
    \mySampleText
    \mySampleText
    \mySampleText
    \mySampleText
    \mySampleText

% Label 3 (same as Label 2)
    \scalebox{0.7}{ % --> Scaled to 70 %
    % minipage is needed since scalebox acts like \mbox (--> no line breaks)
    % Found here (German): https://de.wikibooks.org/wiki/LaTeX-W%C3%B6rterbuch:_scalebox
    \begin{minipage}{\the\textwidth}
        \textbf{Label 3}
        \mySampleText
        \mySampleText
        \mySampleText
        \mySampleText
        \mySampleText
    \end{minipage}
    }

\end{labels}
% ----- End of Labels -----
\end{document}

enter image description here

1
  • I have upvoted this answer, but an automatic solution would be better. Apr 28, 2018 at 3:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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