In a scenario where TeX documents are generated by a script the challenge is to nicely fit text of variable length into boxes of fixed size.

There's a default font size suited for 80% of the cases but if a box would become overfull, the TeX engine* should reduce the font size of that box until the text fits in the box.

Is this possible?

(Sorry for not providing sample code by I think it's clear from the explanation.)

If this is a scenario where LuaTeX works well, I'm happy to look into it.

| improve this question | | | | |
  • This is possible. You needn't Lua prefix before TeX. The solution with classical TeX can be found at petr.olsak.net/opmac-tricks-e.html#scaleto – wipet Apr 15 '15 at 11:16
  • This seems to be for a given width only, not a multi-line paragraph with many words. – Sir Vivor Apr 15 '15 at 11:22
  • 1
    You should supply a sample code though, why make anyone considering an answer make their own test file? – David Carlisle Apr 15 '15 at 11:27
  • do you mean limit the vertical size to avoid overfull vboxes? – David Carlisle Apr 15 '15 at 11:32
  • Scale nothing if box not full. Reduce font size if necessary to fit text in a fixed box. – Sir Vivor Apr 15 '15 at 11:34

Yet again tcolorbox answer. First with a macro version:

bottom=0mm,center upper,valign=center,

%% \mybox[<optional>]{<width>}{<height>}{<content>}


enter image description here

Now the environment form:

enhanced,watermark text={\tcbfitsteps},colframe=blue!75!black,colback=white,#1}



enter image description here

| improve this answer | | | | |

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.