1

Which LaTeX packages can I use to center, scale, and wrap text such that the following conditions are met:

  • If the text isn't a wide as the container, scale the up text to fit.
  • If the text is wider than the container, scale the text down to fit.
  • In the case that text is scaled down, wrap the text to prevent ending up with one tiny, unreadable paragraph.

I've tried parbox, pbox, tabular, and adjustbox, none quite meeting all three conditions.

Here's the gist:

\documentclass{article}

\usepackage[percent]{overpic}
\usepackage[outline]{contour}
\usepackage{fontspec}
\newfontfamily\headingText[Color=FFFFFF]{KnowYourProduct}

\newcommand{\myFrame}[1]  {
    \begin{overpic}[width=6cm,height=3cm,grid,tics=10]{Template}
        \put (8,25) {
            {\contourlength{0.025em}\contour{black}{\headingText #1}}
        }
    \end{overpic}
}   

\begin{document}

\myFrame{Title}
\myFrame{This Is A Long Title}
\myFrame{This title is so long that if you're still reading it you may want to reevaluate how you are presently squandering your personal time.}

\end{document}
twip
  • 325
  • Done. Was there was an implied "Learn a little more and try this again" with the previous comment? Should I be modifying this question? – twip Sep 11 '14 at 21:38
  • 1
    No sorry, I was choosing the wrong stock comment ;-) It was fine! Welcome to TeX.SX (this was no stock comment! ;-)) –  Sep 11 '14 at 21:39
  • 1
    The question is when does text become too small to be readable. – John Kormylo Sep 12 '14 at 00:58
  • 1
    egreg has a related answer here: http://tex.stackexchange.com/questions/33417/adjust-font-size-on-the-fly/33897#33897. I had a related answer here: http://tex.stackexchange.com/questions/123614/making-the-text-fit-in-a-specific-space-in-latex/123650#123650. And then there is this question: http://tex.stackexchange.com/questions/26002/fit-text-into-given-box-by-adjusting-the-fontsize – Steven B. Segletes Sep 12 '14 at 01:57

1 Answers1

1

Sorry, but I had enough problems without having to deal with your fonts, etc.

\documentclass{article}
\usepackage{graphicx}

\newlength{\tempwidth}
\newlength{\temptest}
\newcount{\templines}

\newcommand{\myFrame}[1]% #1 = text
{\settowidth{\tempwidth}{#1}%
\ifdim\tempwidth>6cm \templines=0
  \loop\advance\templines by 1
    \temptest = 2\baselineskip% 6cm (width) / 3cm (height) = 2
    \multiply\temptest by \templines
    \multiply\temptest by \templines
    \ifdim\tempwidth>\temptest\repeat
  \divide\temptest by \templines
  \fbox{\resizebox*{6cm}{3cm}{\parbox{\temptest}{#1}}}%
\else \fbox{\resizebox*{6cm}{3cm}{#1}}%
\fi}

\begin{document}

\myFrame{Title}

\myFrame{This Is A Long Title}

\myFrame{This title is so long that if you're still reading it you may want to reevaluate how you are presently squandering your personal time.}

\end{document}

boxes

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • Not looking for the behavior in the middle box, but I'm working with this on a better solution including all my fonts, etc. I think height is also a constraint in the first case: essentially, there's a magical goldilocks zone here. – twip Sep 12 '14 at 07:04
  • The \parbox solution can be used for smaller titles, but at some point it breaks down. – John Kormylo Sep 12 '14 at 13:04
  • Good point. I really had no idea how deep this combination of wants was going to go. – twip Sep 12 '14 at 16:32