TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to auto-resize some text that appears in a few nodes. Basically if the text is too large (overfull-hbox, etc) then set the font size smaller and continue. Does anyone know how to do this?

Why automatic and not fixed manually? The idea is that this document will be populated automatically and have latex run on it and the resulting documents are displayed. There would be a substantial number of these so it is unfeasable to fix it by hand.

share|improve this question
ipavlic answered it but the problem with that is the node hasn't been typeset yet, and I didn't know about boxes. Thanks though – Trevor A. Apr 15 '11 at 0:29
up vote 2 down vote accepted

A sketch of one possible approach is presented below:


%scalebox needs graphicx
%settototalheight uses calc
%define some lengths



%create a box which will contain text you want to put in
\sbox{\mybox}{\parbox{\nodewidth}{Ceterum censeo Carthaginem esse delendam}}
%measure its height
%calculate the ratio of box’s height and available space in node

%resize your box to fit inside node; keep width-to-height ratio using !, and resize height as necessary
\node [rectangle, minimum width=\nodewidth, minimum height=\nodeheight, draw=black] {\resizebox{!}{\pgfmathresult\nodeheight}{\usebox{\mybox}}};


%here is the original box, which is too big:

The result:


It is far from ideal -- note that text could be bigger if I were to appropriately resize just the text and not the box containing it.

share|improve this answer
As a side note, tikz nodes automatically expand to accommodate text, do they not? – ipavlic Apr 13 '11 at 10:10
Thanks, I should be able to get this to work. The nodes would resize like you said (or that is my understanding as well, if they do not have a fixed size). The size of the nodes is important and must be preserved. Thanks Again. – Trevor A. Apr 13 '11 at 13:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.