Search code examples
latextikz

How to float text around a tikz picture in a LaTeX theorem environment?


I don't like to use an outer picture editor just like xfig, because it don't make work. Here's an example:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[magyar]{babel}

\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amstext}

\usepackage{tikz}
\usepackage{cutwin}

\newtheorem{thm}{tétel}

\begin{document}
    \section{Téglalap}
        \begin{thm}
            A téglalap a területét az oldalhosszakból az
            $$A=ab$$
            képlettel számolhatjuk ki.
        \end{thm}
        \begin{proof}
            A bizonyítás grafikusan igen jól szemléltethető. Vegyünk fel ugyanis egy $a+b$ oldalhosszúságú négyzetet, és ebben helyezzük el a négy egybevágó téglalapot.
            \opencutleft\begin{cutout}{3}{0pt}{\textwidth}{1}
                \begin{tikzpicture}
                    \draw (0,0) -- (0,1) -- (3,1) -- (3,0) -- cycle;
                    \draw (3,0) -- (4,0) -- (4,3) -- (3,3) -- cycle;
                    \draw (4,3) -- (4,4) -- (1,4) -- (1,3) -- cycle;
                    \draw (0,4) -- (1,4) -- (1,1) -- (0,1) -- cycle;
                \end{tikzpicture}
            \end{cutout}
            A nagy négyzet területe $A=(a+b)^2$, a belső kis négyzet oldalhossza $a-b$, így a területe $A'=(a-b)^2$. A kettő különbsége lesz a négy téglalap területének összege:
            \begin{align*}
                (a+b)^2-(a-b)^2&=a^2+b^2+2ab-(a^2+b^2-2ab)=\\
                &=4ab=4A.
            \end{align*}

            Innen egy téglalap területe az egybevágóság miatt már megkapható, és ez pont a tétel állítása.
        \end{proof}
\end{document}

The problem is that the picture slips over the upper text, and the space above is empty, the begins the following text. When I alter the spaces, the picture goes evrywhere, and lowering those numbers it's getting closer the planned place, with awaiting it at the number 0. But when I write zero, the translator throws errors because of it and outs. The exact message says "Missing number, treated az zero".


Solution

  • wrapfig package does not to help inside proof environment, so I'll post a very simple no-float alternative to the good answer by @dfri.

    \documentclass{article}
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    \usepackage[magyar]{babel}
    
    \usepackage{amsthm}
    \usepackage{amsmath}
    \usepackage{amssymb}
    \usepackage{amstext}
    
    \usepackage{tikz}
    %\usepackage{cutwin}
    
    \newtheorem{thm}{tétel}
    
    \begin{document}
        \section{Téglalap}
        \begin{thm}
            A téglalap a területét az oldalhosszakból az
            $$A=ab$$
            képlettel számolhatjuk ki.
        \end{thm}
        \begin{proof}
            A bizonyítás grafikusan igen jól szemléltethető. Vegyünk fel ugyanis egy $a+b$ oldalhosszúságú négyzetet, és ebben helyezzük el a négy egybevágó téglalapot.
            \begin{center}
                \begin{tikzpicture}
                \draw (0,0) -- (0,1) -- (3,1) -- (3,0) -- cycle;
                \draw (3,0) -- (4,0) -- (4,3) -- (3,3) -- cycle;
                \draw (4,3) -- (4,4) -- (1,4) -- (1,3) -- cycle;
                \draw (0,4) -- (1,4) -- (1,1) -- (0,1) -- cycle;
                \end{tikzpicture}
            \end{center}
            A nagy négyzet területe $A=(a+b)^2$, a belső kis négyzet oldalhossza $a-b$, így a területe $A'=(a-b)^2$. A kettő különbsége lesz a négy téglalap területének összege:
            \begin{align*}
                (a+b)^2-(a-b)^2&=a^2+b^2+2ab-(a^2+b^2-2ab)=\\
                &=4ab=4A.
            \end{align*}
    
            Innen egy téglalap területe az egybevágóság miatt már megkapható, és ez pont a tétel állítása.
        \end{proof}
    \end{document}
    

    outputs:

    screenshot

    Notice that I only edited lines 25 and 32 (and commented \usepackage{cutwin} in line 12): center environment behaves properly also with text of arbitrary length before \section{}.

    I'll post an update if I work out some good setting for cutout environment, which is meant to be used in theorem-like environments.