Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Compressing text to a given width

69 views
Skip to first unread message

Sven Siegmund

unread,
Jan 22, 2012, 3:36:37 PM1/22/12
to
Hello,

my problem is fairly complex but boils down to a few LaTeX/pstricks
commands which would check the width of a given string of characters,
and if this exceeds certain limits, it would compress it to a given
width (skewing the font, resulting in an ugly typesetting result, but
nobody would really care).

Please look at this image which hopefully explains things with all the
necessary details: http://dl.dropbox.com/u/860437/compressing%20text%20to%20given%20width.png

Thanks for any help.

S.

Peter Flynn

unread,
Jan 22, 2012, 7:18:02 PM1/22/12
to
Something like:

\documentclass{article}
\usepackage{graphicx,calc,xcolor}
\newlength{\signwidth}
\newlength{\phrasewidth}
\setlength{\signwidth}{2in}
\newcommand{\dispcolor}{red}
\newcommand{\displaybox}[1]{%
\fcolorbox{\dispcolor}{white}{\hbox to\signwidth{\strut#1\hfil}}}
\newcommand{\squeeze}[2][\relax]{\begingroup
\if#1\relax
\renewcommand{\displaybox}[1]{##1}%
\else
\renewcommand{\dispcolor}{#1}%
\fi
\fboxsep0pt\fboxrule.1pt
\setlength{\phrasewidth}{\widthof{#2}}%
\ifdim\phrasewidth>\signwidth
\displaybox{\resizebox{\signwidth}{\heightof{#2}}{#2}\hfil}%
\else\displaybox{#2}%
\fi
\endgroup}
\begin{document}
\sffamily\Huge
\squeeze[red]{Hobbiton}
\par\bigskip
\squeeze{Encircling Mountains}
\end{document}

///Peter

Donald Arseneau

unread,
Jan 23, 2012, 1:41:50 AM1/23/12
to
Sven Siegmund <sven.s...@gmail.com> writes:

> my problem is fairly complex but boils down to a few LaTeX/pstricks
> commands which would check the width of a given string of characters,
> and if this exceeds certain limits, it would compress it to a given
> width (skewing the font, resulting in an ugly typesetting result, but
> nobody would really care).

Does pdftex do font compression as well as font extension?



Donald Arseneau as...@triumf.ca

Paweł Wlaź

unread,
Jan 23, 2012, 4:25:38 AM1/23/12
to


On Sun, 22 Jan 2012, Sven Siegmund wrote:

> Hello,
>
> my problem is fairly complex but boils down to a few LaTeX/pstricks
> commands which would check the width of a given string of characters,
> and if this exceeds certain limits, it would compress it to a given
> width (skewing the font, resulting in an ugly typesetting result, but
> nobody would really care).

As I understand you just want the method of compressing to desired
width (and the rest, like drawing the boxes, arrows e.t.c. is another
problem you know how to deal with). Try this simple code:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass{article}
\usepackage{graphicx} %%% for \resizebox
\usepackage{calc} %%% for \widthof

\newlength{\mylength}
\newcommand\compress[2]{%
\setlength{\mylength}{\widthof{#1}}%
\ifdim\mylength>#2%
\resizebox{#2}{\height}{#1}%
\else
#1%
\fi}

\begin{document}
\compress{Andy}{1cm}

\compress{Andy Larkin}{1cm}
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

PW

Sven Siegmund

unread,
Jan 28, 2012, 6:39:22 AM1/28/12
to
> As I understand you just want the method of compressing to desired
> width (and the rest, like drawing the boxes, arrows e.t.c. is another
> problem you know how to deal with). Try this simple code:

Dziękuję bardzo Paweł. That's what I needed. All the other things are
taken care of. Your minimal example works and is perfectly
understandable.

Cheers,

Sven.
0 new messages