[pdftex] howto adjust \fontsize to \textwidth

Verwalter Dr.Betz kla at fh-landshut.de
Mon Apr 15 04:25:38 CEST 2002


The following is a working example on how to maximize the fontsize (named
\MAXSIZE) of a textbox (named \INTRO), so that the textbox will fit
exactly to \textwidth of the page.

I have but one problem with it: I find it hard to display the text
centered *within* the textbox.
If I format it centered using \begin{center} or {\hfill #1 \hfill},
I can no longer use the same textbox for calculating maximum fontsize.

Thanks for any help,
Herbert
kla at fh-landshut.de

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  example:

\documentclass[pdftex,twoside]{article}
\usepackage{pslatex}% contains PostscriptHelvetica as SansSerif(Lipkin155)
\usepackage{calc}
\usepackage{ifthen}

\newcommand{\INTRO}{%
\vbox{%\begin{center}%
\hbox{Office for}\par%
\hbox{Traditional Medicine}\par%
\hbox{and}\par%
\hbox{Esoteric Thinking}\par% \par for line spacing above
%\end{center}
%\par\vspace{0 pt plus 1 fill}% \vfill here not working?
%\parbox{\textwidth}{\Huge\centering Join us!}%
}}%

\unitlength=1mm
\renewcommand{\familydefault}{\sfdefault}% serifenlos


\begin{document}

%calculate maximum scriptsize \MAXSIZE from \INTRO:
\newlength{\targetsize}\setlength{\targetsize}{\textwidth}
\newlength{\MAXSIZE}
\newsavebox{\MAXBOX}
\newcounter{i}
\setcounter{i}{1}
\whiledo{\wd\MAXBOX<\targetsize}{%
\setlength{\MAXSIZE}{1pt*\value{i}}
\fontsize{\MAXSIZE}{\MAXSIZE}\selectfont
\sbox{\MAXBOX}{\INTRO}
\stepcounter{i}
}
\addtocounter{i}{-2}
\setlength{\MAXSIZE}{1pt*\value{i}}
\showthe\MAXSIZE
\normalsize\normalfont


\newcommand{\MAXFONT}[1]{%
\fontsize{\MAXSIZE}{\MAXSIZE}\selectfont #1 \normalfont\normalsize}


\clearpage\pagestyle{empty}
\begin{center}

\hfil\vspace{40mm}\par
\fbox{\MAXFONT{\INTRO}}
\par\rule{0.5\textwidth}{1pt}
\par\vspace{0 pt plus 1 fill}%
\fbox{\MAXFONT{Here we are \dots}}%
\end{center}

\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




More information about the pdftex mailing list