[Tex/LaTex] How to put auto width to floatingfigure

floatsplotwidthwrap

I'm trying to wrap an generated graphic with text. But I cannot find what I have to put instead of 6cm in \begin{floatingfigure}[l]{6cm} to let LaTeX designate correct width like it does with height.

\documentclass[10pt]{article}
\usepackage{pstricks-add}
\usepackage{floatflt}
\pagestyle{empty}
\begin{document}
 text text text text text text text text text text text text text text text text text text

\begin{floatingfigure}[l]{6cm}
\psset{xunit=1.0cm,yunit=1.0cm,algebraic=true,dotstyle=o,dotsize=3pt
0,linewidth=0.8pt,arrowsize=3pt 2,arrowinset=0.25}
\begin{pspicture*}(-1,-1)(5,4)
\psaxes[labelFontSize=\scriptstyle,xAxis=true,yAxis=true,Dx=1,Dy=1,ticksize=-2pt 0,subticks=2]{->}(0,0)(-1,-1)(5,4)[AAA,140] [BBB,-40]
\begin{scriptsize}
\psdots[dotstyle=*,linecolor=blue](2.48,3.3)
\rput[bl](2.56,3.42){\blue{$A$}}
\end{scriptsize}
\end{pspicture*}
\end{floatingfigure}
text text text text text text text text text text text text text text text text text text 
\end{document}

Ouch, I have a new problem, if last text is too short and there's a new section or subsection following, text in new section overwrite graphic. There is solution for this or only should I avoid this kind of situations?

\documentclass[10pt]{article}
\usepackage{pstricks-add}
\usepackage{floatflt}

\newsavebox{\floatbox}

\pagestyle{empty}
\begin{document}
 text text text text text text text text text text text text text text text text text text

\sbox{\floatbox}{%
\psset{xunit=1.0cm,yunit=1.0cm,algebraic=true,dotstyle=o,dotsize=3pt 0,
linewidth=0.8pt,arrowsize=3pt 2,arrowinset=0.25}
\begin{pspicture*}(-1.2,-1.2)(5,4)
\psaxes[labelFontSize=\scriptstyle,xAxis=true,yAxis=true,Dx=1,Dy=1,ticksize=-2pt 0,
subticks=2]{->}(0,0)(-1,-1)(5,4)[AAA,140] [BBB,-40]
\scriptsize
\psdots[dotstyle=*,linecolor=blue](2.48,3.3)
\rput[bl](2.56,3.42){\blue{$A$}}
\end{pspicture*}}

\begin{floatingfigure}[l]{1.1\wd\floatbox}
\usebox{\floatbox}
\end{floatingfigure}
text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text
\section{New section}
text text text
\end{document}

Best Answer

You can measure the box before using it:

\documentclass[10pt]{article}
\usepackage{pstricks-add}
\usepackage{floatflt}

\newsavebox{\floatbox}

\pagestyle{empty}
\begin{document}
 text text text text text text text text text text text text text text text text text text

\sbox{\floatbox}{%
  \psset{xunit=1.0cm,yunit=1.0cm,algebraic=true,dotstyle=o,dotsize=3pt 0,
    linewidth=0.8pt,arrowsize=3pt 2,arrowinset=0.25}
  \begin{pspicture*}(-1.2,-1.2)(5,4)
  \psaxes[labelFontSize=\scriptstyle,xAxis=true,yAxis=true,Dx=1,Dy=1,ticksize=-2pt 0,
    subticks=2]{->}(0,0)(-1,-1)(5,4)[AAA,140] [BBB,-40]
  \scriptsize
  \psdots[dotstyle=*,linecolor=blue](2.48,3.3)
  \rput[bl](2.56,3.42){\blue{$A$}}
\end{pspicture*}}

\begin{floatingfigure}[l]{1.1\wd\floatbox}
\usebox{\floatbox}
\end{floatingfigure}
text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text
\end{document}

I've made some changes to the body of the picture; for setting the width I used 1.1\wd\floatbox, but also

\dimexpr\wd\floatbox+1em\relax

could be used to have a known clearance. The box bin \floatbox can be reused at will in the same way.

Related Question