Text FormattingText width in Paragraph mode

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
WarGoX
Posts: 3
Joined: Sun Nov 09, 2008 11:08 am

Text width in Paragraph mode

Post by WarGoX »

Hi, i'm trying to create some personalized color-box using TikZ and PGF. What i want to do is pass the text to the macro and that the color-box calc it's own "text width".

I done this parcially using an lrbox:

Code: Select all

\begin{lrbox}{\capbox}\footnotesize#1\end{lrbox}%
\settowidth{\capwidth}{\usebox{\capbox}}%
With this in \capwidth i have the width of the text. Which works fine if the text that i pass to the macro is "example, word, jhon doe". But if i pass something like: "example \\ word \\ jhon" if tails. This is because lrbox works in LR-mode (only one line). My question is, exist a way for "calculate" the textwidth of a Paragraph-mode text?

P.S: \parbox{}{} works for "paint" a box, but i need to store the box on a command to later extract the width.

Thanks!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
WarGoX
Posts: 3
Joined: Sun Nov 09, 2008 11:08 am

Text width in Paragraph mode

Post by WarGoX »

Well, this is an auto-reply but in this way it keeps stored for the ones that need to do something like this.

The answer for my need was using the varwidth package, so i put this inside a lrbox environment and then with \usebox{} i can extract the width of the resulting box, the resulting code is:

Code: Select all

\begin{lrbox}{\capbox}
	\begin{varwidth}{.5\textwidth}
		\footnotesize#1
	\end{varwidth}
\end{lrbox}
\settowidth{\capwidth}{\usebox{\capbox}}%
Post Reply