Formatting text in paragraph mode inside a frame of fixed dimensions

Denis Girou Denis.Girou at idris.fr
Thu Oct 29 22:11:00 CET 1998


-----------------------------------------------------------------------------
This is the PSTricks mailing list, devoted to discussions about computational
graphics in (La)TeX using the PSTricks package from Timothy van Zandt.
For help using this mailing list, see instructions at the end of message.
-----------------------------------------------------------------------------

  Somebody outside the list ask some time ago how to format a text in
paragraph mode and to put it in a box exactly of fixed dimensions (of course
to be able to align several ones together).

  So, giving the dimensions and the text, we must compute the horizontal width 
of the text (deducing the rules and margins of both sides), center it
vertically and format it in paragraph mode.

  Here is the solution I had proposed, which can be useful in other
circumstances, I think (one interesting feature is to use PSTricks dimensions,
so to be able to accept values relative to the current value of the unit
parameter):

\documentclass{article}

\usepackage{pstricks}

\setlength{\parindent}{0cm}

\pagestyle{empty}

\makeatletter

\def\MyBox{\pst at object{MyBox}}
\def\MyBox at i#1#2#3{{%
\use at par                        % Local parameters
\if at star\solid at star\fi          % Stared version
\pssetlength{\pst at dimc}{-\psframesep}
\psaddtolength{\pst at dimc}{-\psframesep}
\psaddtolength{\pst at dimc}{-\pslinewidth}
\psaddtolength{\pst at dimc}{-\pslinewidth}
\pssetlength{\pst at dima}{#1}
\psaddtolength{\pst at dima}{\pst at dimc}
\pssetlength{\pst at dimb}{#2}
\psaddtolength{\pst at dimb}{\pst at dimc}
\setbox\z@\vbox to\pst at dimb{\hsize\pst at dima\sloppy\vfil#3\vfil}%
\psframebox{\box\z@}}}

\makeatother

\begin{document}

\MyBox{5cm}{2cm}{Text to format in paragraph mode.}

\vspace{1cm}
\MyBox[framesep=0.3]{5}{2}{Text to format in paragraph mode.}

\vspace{1cm}
\MyBox[framesep=1,linewidth=0.2]{5}{4}{Text to format in paragraph mode.}

\vspace{1cm}
\MyBox[unit=0.5]{5}{4}{Text to format in paragraph mode.}

\vspace{1cm}
\MyBox*[linecolor=lightgray]{5}{2}{Text to format in paragraph mode.}

\vspace{1cm}
\MyBox[linecolor=red,fillstyle=solid,fillcolor=yellow]
      {5}{2}{\centering\itshape Text to format in paragraph mode.}

\end{document}

D.G.

-----------------------------------------------------------------------------
The list interface (subscription, information, access to the archives) is on:
http://www.tug.org/cgi-bin/lwgate/pstricks
Otherway to unsubscribe, send mail to pstricks-request at mail.tug.org
with a blank subject and in body the line unsubscribe <email-address>
-----------------------------------------------------------------------------



More information about the PSTricks mailing list