3

When there is not enough space for TikZ picture at the end of a text, it will goes to the next page, and leaves an empty space after the text. Is there a standard method for putting TikZ picture in the middle of text, flowing the text to the next page, instead of pushing TikZ picture?

A possible method is using wrapfig page, to put TikZ picture inside wrapfigure. This is a flexible method for floating smaller (e.g. half-sized) TikZ picture within text. I am curious if there is a simpler method for arranging full-width TikZ picture within text to avoid any gap throughout the text.

Here is a very simple example:

\documentclass{article}
\usepackage{mdframed}
\usepackage{lipsum}
\usepackage{tikz}

\begin{document}
\begin{mdframed}
    \lipsum[1-2]
\begin{tikzpicture}
   \draw[fill=blue] (0,0) rectangle (11,11);
\end{tikzpicture}
\end{mdframed}
\end{document}

Since the TikZ picture does not fit in the first page, it will goes to the second page and leave an empty space at the bottom of first page. I want to keep the TikZ picture in the first page, and push the excess text to the second page.

In a long text with several TikZ pictures, I want to avoid any gap within the text.

percusse
  • 157,807
Googlebot
  • 4,035
  • are you putting your tikzpicture within a figure environment? – cmhughes Jun 03 '12 at 22:49
  • @cmhughes no, I have text within mdframed and simply added tikzpicture at the end of my text. – Googlebot Jun 03 '12 at 22:50
  • 1
    As @percusse suggests, please compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it.

    This will also serve as a test case and ensure that the solution actually works for you.

    – Peter Grill Jun 04 '12 at 00:35
  • @percusse I added a simple example explaining the issue. – Googlebot Jun 04 '12 at 08:23
  • @PeterGrill Probably, I was unable to express the issue. The case is in basic usage of tikz incorporated in the body of text. I added an example to clarify my issue. – Googlebot Jun 04 '12 at 08:25
  • 3
    The problem is independent of TikZ. What you get with TikZ is a box. TikZ can place this box relatively to the current line (and baseline) or relatively to the page (with overlay). But when the box is in the flow, it's a TeX's box and you need to use the tools linked to floats, figures etc. This is the problem to place a box or a figure in the flow. With pdftex, there are several limitations and this problem is sometimes not easy. – Alain Matthes Jun 04 '12 at 08:33
  • @Altermundus I did not claim that it is problem of TikZ. I am looking for the best method (probably simplest) to overcome this problem. Well adjustment of TikZ pictures within text! – Googlebot Jun 04 '12 at 08:43
  • 2
    Use a figure environment around your tikzpicture. – Stephan Lehmke Jun 04 '12 at 08:55
  • @StephanLehmke as I stated in the original question, I am currently using wrapfig to do so. I just asked this question to find if there is a simpler approach for this purpose. – Googlebot Jun 04 '12 at 09:08
  • 1
    @Ali As you stated, wrapfig is good for narrow pictures, but not for full-width ones. figure (which you can use without a dedicated package) is for full-width pictures. – Stephan Lehmke Jun 04 '12 at 09:11
  • 1
    But I guess a floating {figure} with an {mdframed} environment won’t work … – Tobi Jun 04 '12 at 09:36
  • @Tobi you're quite right! This is the reason that I tried wrapfig, and am looking for a better solution. This is float within float and leads to ! LaTeX Error: Not in outer par mode. – Googlebot Jun 04 '12 at 09:41
  • You can try "tcolorbox" from http://www.ctan.org/tex-archive/macros/latex/contrib/tcolorbox – sandu Jun 04 '12 at 09:53
  • @sandu You mean replacing mdframed with tcolorbox? tcolorbox is absolutely awesome, but it is not as flexible as mdframed like spreading the frame over multiple pages. – Googlebot Jun 04 '12 at 10:21
  • @Ali: Please rephrase your question to properly reflect your requirements. You don't mention your need of mdframed at all in the text, but it changes the situation drastically! There is no need to append new material with an "Edit" headline. It's normally much better to simply rephrase the exiting part as required. Older revisions of every posts are still accessible anyway. – Martin Scharrer Jun 07 '12 at 10:59
  • @MartinScharrer you are quite right! I edited the question according to your instruction. I hope to find a solution now. – Googlebot Jun 07 '12 at 11:30

1 Answers1

5

The package mdframed also tcolorbox use internal saveboxes. Inside such TeX-construction you can't use any floating material. So you have to adjust manual or avoid such an environment.

Marco Daniel
  • 95,681