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 have a TikZ figure that appears as follows. The figure also has a caption.

I'd like the caption to fill up that blank space in the bottom-right and bleed over into the space it current occupies.

Is there a way to do this?

Thanks!

fig

share|improve this question
1  
Are these three diagrams aligned inside a single TikZ picture or are they three separate environments aligned using additional code? In the first case it should be difficult, but the second one might be done by placing the last figure in a wrapfig? –  Martin Scharrer Apr 13 '12 at 23:34
    
They were all inside a single TikZ environment, but you have a good idea there. –  Richard Apr 14 '12 at 4:02

2 Answers 2

up vote 9 down vote accepted

The following is a mock-up of what can be done. It is easiest to set the caption manually rather than rely on \caption, since \caption interferes with the alignment:

enter image description here

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{document}
\tableofcontents
\listoffigures
\section{A section}
\lipsum[1]

\begin{figure}[t]
  % Your images
  \rule{150pt}{50pt} \hfill \rule{150pt}{50pt} \par\bigskip  
  \rule{150pt}{50pt} \par

  % The caption
  \vspace*{\dimexpr-\parskip-50pt\relax}% Skip backwards over last left-aligned image
  \parshape 6 % Set flow of caption: 6 lines...
    .5\textwidth .5\textwidth % First 5 start @ .5\textwidth with
    .5\textwidth .5\textwidth % a width of .5\textwidth
    .5\textwidth .5\textwidth
    .5\textwidth .5\textwidth
    .5\textwidth .5\textwidth
    0pt \textwidth % last (sixth) line restores regular flow ad infinitum
  \makeatletter
  % Setting of actual caption (this is taken from latex.ltx)
  \refstepcounter\@captype% Increase float/caption counter
  \addcontentsline{\csname ext@\@captype\endcsname}{\@captype}% Add content to "List of..."
    {\protect\numberline{\csname the\@captype\endcsname}{ToC entry}}%
  \csname fnum@\@captype\endcsname: % Float caption + #
  \makeatother
  % Actual caption
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
    Pellentesque eget lectus a magna scelerisque iaculis. Duis ac mi sit amet 
    ligula bibendum feugiat. Aliquam vehicula sem id mauris lacinia suscipit. 
    Curabitur nec ipsum mi. Nulla elit mi, rutrum sed placerat id, congue non 
    orci. Proin non orci et metus sodales tincidunt sit amet non mi. Vestibulum 
    libero nibh, blandit rhoncus tempus convallis, scelerisque a dui. Duis 
    ullamcorper malesuada metus eget dapibus. Nam et luctus mauris. Aliquam 
    nulla turpis, adipiscing sed viverra a, ultrices id nibh. Etiam tincidunt 
    dui in magna vestibulum aliquam. Sed sagittis lacinia lectus sed malesuada. 
    Nunc tristique sagittis urna vel interdum. Donec id turpis neque, et placerat 
    sem. Curabitur nec tincidunt leo. Nam lobortis bibendum enim, semper 
    scelerisque erat molestie at.%
\end{figure}

\lipsum[2]
\end{document}

The steps in terms of setting the caption are:

  1. Move up vertically so as to be on the same level as the last left-aligned image;
  2. Set the paragraph style to be indented for a certain number of lines (using \parshape);
  3. Do the necessary ToC-level stuff (taken from latex.ltx); and
  4. Set the actual caption.

The above solution is general enough that you could use it in a table environment as well. Moreover, it could be condensed into an environment similar to that of wrapfigure (from the wrapfig package) with some arguments to specify the appropriate modifications. However, since this seems to have one-time-usage, as-is is probably sufficient.

share|improve this answer
    
I wonder why wrapfig does not work here? (I didn't tried it). You need the caption as paragraph then. –  Martin Scharrer Apr 13 '12 at 23:32

I had the same problem, but not with TikZ figures but with normal figures using \includegraphics and subfigures. One problem hereby was to vertically align the subfigures while keeping labels below subfigures. Here the adjustbox packaged helped. I know that subfig is listed in l2tabu und subcaption is suggested as a replacement. But I didn't get it to work with subcaption, as adjustbox didn't worked well. The actual cool wrapping code is copied from above. So this answer contributes more to the integration with subfigures rather solving the wrapping problem.

\documentclass{article}
\usepackage[caption=false]{subfig}
\usepackage[export]{adjustbox}
\usepackage{lipsum}

\begin{document}
\begin{figure}
  \begin{center}
    \subfloat[][]{\rule{0.49\textwidth}{5cm}}\hfill
    \subfloat[][]{\rule{0.49\textwidth}{5cm}}\par
    \subfloat[][]{\adjustbox{valign=t}{\rule{0.245\textwidth}{2cm}}}\hfill
    \subfloat[][]{\adjustbox{valign=t}{\rule{0.245\textwidth}{2cm}}}\hfill
    \subfloat[][]{\adjustbox{valign=t}{\rule{0.49\textwidth}{5cm}}}\par
  \end{center}

  % The caption
  \vspace*{\dimexpr-\parskip-2.9cm\relax}% Skip backwards over last left-aligned image
  \parshape 8 % Set flow of caption
  0pt 0.48\textwidth %
  0pt 0.48\textwidth %
  0pt 0.48\textwidth
  0pt 0.48\textwidth
  0pt 0.48\textwidth
  0pt 0.48\textwidth
  0pt 0.48\textwidth
  0pt \textwidth % last line restores regular flow ad infinitum
  \makeatletter
  % Setting of actual caption (this is taken from latex.ltx)
  \refstepcounter\@captype% Increase float/caption counter
  \addcontentsline{\csname ext@\@captype\endcsname}{\@captype}% Add content to "List of..."
  {\protect\numberline{\csname the\@captype\endcsname}{ToC entry}}%
  \csname fnum@\@captype\endcsname: % Float caption + #
  \makeatother
  \protect\lipsum*[2]
\end{figure}
\end{document}

Which renders to:

wrapedcaption

share|improve this answer

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.