Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

1 Answer 1

up vote 2 down vote accepted

A sketch of one possible approach is presented below:

\documentclass[12pt]{article}

\usepackage{tikz}
%scalebox needs graphicx
\usepackage{graphicx}
%settototalheight uses calc
\usepackage{calc}
%define some lengths
\newlength\nodeheight
\setlength{\nodeheight}{1cm}

\newlength\nodewidth
\setlength{\nodewidth}{3cm}

\newlength\myboxheight

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

\centering
\begin{tikzpicture}
%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}}};
\end{tikzpicture}

\bigskip

%here is the original box, which is too big:
\usebox{\mybox}
\end{document}

The result:

Scalebox

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
1  
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

 
discard

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.