3

In my document I have a huge data flow graph that is exactly one page high. Since it is not very wide I'd like to have it on the left/right side of one page while having normal text on the other side.

Most intuitive way would be to use wrapfig, but this package always places the figure at the very end of the current chapter. This is kind of strange behavious since I can verify by changing the wrapfigure environment to a figure environment that the figure does fit on one page.

Here's an MWE:

\documentclass{scrbook}

\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,
    decorations.pathreplacing,decorations.pathmorphing,shapes,
    matrix,shapes.symbols}
\usepackage{wrapfig}

\def\n{3}

\newcommand{\bridgedblock}[1]{
    % args 1: num featuremaps, 2: divide by two, 3: fill color, 4: name prefix
    \node[normalnode] (#1-node1) {\scriptsize label1};
    \begin{scope}[node distance=0.25cm]
        \node[normalnode] (#1-node2) {\scriptsize label2};
    \end{scope}

    \path (#1-node1) edge (#1-node2);
    \path[draw, shorten >=0pt] ($(#1-node1.north) + (0cm, 0.175cm)$) -| ($(#1-node1) + (2cm,-0.5cm)$) |- ($(#1-node2.south) - (0cm, 0.125cm)$);
}

\newcommand{\insertpicture}{
    \begin{tikzpicture}[node distance=0.55cm, start chain=going below, shorten >=1pt, ->]
        \tikzstyle{normalnode}=[draw, rectangle, text centered, on chain,
                          minimum height=0.3cm, text width=3cm]
        \tikzstyle{empty}=[text centered, on chain]

        \pgfmathtruncatemacro{\boundary}{\n - 1}

        \node[empty] (input) {\scriptsize x};
        \node[normalnode] (init-node) {\scriptsize label1}; 

        \foreach \twopow in {32, 16, 8} {

            \bridgedblock{\twopow-1};
            \foreach \name [evaluate=\name as \pred using int(\name - 1)] in {2,...,\boundary} {
                \bridgedblock{\twopow-\name};
                \path (\twopow-\pred-node2) edge (\twopow-\name-node1);
            }
            \bridgedblock{\twopow-last}
            \path (\twopow-\boundary-node2) edge (\twopow-last-node1);
        }

        \node[empty] (noboxnode) {\scriptsize noboxnode};
        \node[normalnode] (lastnode) {\scriptsize lastnode};
        \node[empty] (output) {\scriptsize};

        \path (input) edge (init-node);
        \path (init-node) edge (32-1-node1);
        \path (32-last-node2) edge (16-1-node1);
        \path (16-last-node2) edge (8-1-node1);
        \path (8-last-node2) edge (noboxnode);
        \path (noboxnode) edge (lastnode);
        \path (lastnode) edge (output);
    \end{tikzpicture}
}

\begin{document}

\chapter{Chapter 1}

\lipsum[1]

\section{Section 1}

\begin{wrapfigure}{O}{0.4\textwidth}
    \centering
    \insertpicture
    \caption{A very very long data flow graph.}
\end{wrapfigure}
\lipsum

\section{Section 2}

\section{Section 3}

\section{Section 4}

\end{document}

What I have already tried:

  • Using package floatflt with floatingfigure yields the same behaviour.
  • Using multicol with environment multicols doesn't show the figure at all. Futhermore it is very uncomfortable since you need to decide which text goes next to the figure.

Maybe some of you know another trick.

  • Is a double column layout (only for the page containing the chart) an option? – Alessandro Cuttin Apr 1 '16 at 11:19
  • Yes, it definitely would be an option. Is there another way to achieve this besides using multicol? Like I wrote above, multicol doesn't work for strange reasons. – mackcmillion Apr 1 '16 at 11:45
4

Wrapfig wants to start at the start of a paragraph, so it's best to get a start of a paragraph at the top of the page to give yourself a full page height:

enter image description here

\documentclass{scrbook}

\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,
    decorations.pathreplacing,decorations.pathmorphing,shapes,
    matrix,shapes.symbols}
\usepackage{wrapfig}

\def\n{3}

\newcommand{\bridgedblock}[1]{
    % args 1: num featuremaps, 2: divide by two, 3: fill color, 4: name prefix
    \node[normalnode] (#1-node1) {\scriptsize label1};
    \begin{scope}[node distance=0.25cm]
        \node[normalnode] (#1-node2) {\scriptsize label2};
    \end{scope}

    \path (#1-node1) edge (#1-node2);
    \path[draw, shorten >=0pt] ($(#1-node1.north) + (0cm, 0.175cm)$) -| ($(#1-node1) + (2cm,-0.5cm)$) |- ($(#1-node2.south) - (0cm, 0.125cm)$);
}

\newcommand{\insertpicture}{
    \begin{tikzpicture}[node distance=0.55cm, start chain=going below, shorten >=1pt, ->]
        \tikzstyle{normalnode}=[draw, rectangle, text centered, on chain,
                          minimum height=0.3cm, text width=3cm]
        \tikzstyle{empty}=[text centered, on chain]

        \pgfmathtruncatemacro{\boundary}{\n - 1}

        \node[empty] (input) {\scriptsize x};
        \node[normalnode] (init-node) {\scriptsize label1}; 

        \foreach \twopow in {32, 16, 8} {

            \bridgedblock{\twopow-1};
            \foreach \name [evaluate=\name as \pred using int(\name - 1)] in {2,...,\boundary} {
                \bridgedblock{\twopow-\name};
                \path (\twopow-\pred-node2) edge (\twopow-\name-node1);
            }
            \bridgedblock{\twopow-last}
            \path (\twopow-\boundary-node2) edge (\twopow-last-node1);
        }

        \node[empty] (noboxnode) {\scriptsize noboxnode};
        \node[normalnode] (lastnode) {\scriptsize lastnode};
        \node[empty] (output) {\scriptsize};

        \path (input) edge (init-node);
        \path (init-node) edge (32-1-node1);
        \path (32-last-node2) edge (16-1-node1);
        \path (16-last-node2) edge (8-1-node1);
        \path (8-last-node2) edge (noboxnode);
        \path (noboxnode) edge (lastnode);
        \path (lastnode) edge (output);
    \end{tikzpicture}
}

\begin{document}

\chapter{Chapter 1}

\lipsum[1]

\section{Section 1}

\enlargethispage{2\baselineskip}
\lipsum[1-3]


\begin{wrapfigure}[44]{o}{0.4\textwidth}
    \centering
    \insertpicture
    \caption{A very very long data flow graph.}
\end{wrapfigure}
\lipsum[4-20]

\section{Section 2}

\section{Section 3}

\section{Section 4}

\end{document}
  • I accepted your answer although I also used @Rmano's trick to scale down the graphics. +1 for the nice trick with the [44] parameter. I didn't know about that specifying the number of lines to be wrapped. – mackcmillion Apr 1 '16 at 16:04
4

I suggest putting your figure in the margin. Actually there doesn't remain enough height on the first page of the chapter to insert it with a simple \InsertBoxR without perturbating the line lengths of the following pages, unless you scale the figure by a small factor. This seems to be due to the insertion of a section title.

Thus I propose this code:

\input{insbox.tex}
\documentclass{scrbook}

\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,
    decorations.pathreplacing,decorations.pathmorphing,shapes,
    matrix,shapes.symbols}
\usepackage{wrapfig}

\def\n{3}

\newcommand{\bridgedblock}[1]{
    % args 1: num featuremaps, 2: divide by two, 3: fill color, 4: name prefix
    \node[normalnode] (#1-node1) {\scriptsize label1};
    \begin{scope}[node distance=0.25cm]
        \node[normalnode] (#1-node2) {\scriptsize label2};
    \end{scope}

    \path (#1-node1) edge (#1-node2);
    \path[draw, shorten >=0pt] ($(#1-node1.north) + (0cm, 0.175cm)$) -| ($(#1-node1) + (2cm,-0.5cm)$) |- ($(#1-node2.south) - (0cm, 0.125cm)$);
}

\newcommand{\insertpicture}{
    \begin{tikzpicture}[node distance=0.55cm, start chain=going below, shorten >=1pt, ->]
        \tikzstyle{normalnode}=[draw, rectangle, text centered, on chain,
                          minimum height=0.3cm, text width=3cm]
        \tikzstyle{empty}=[text centered, on chain]

        \pgfmathtruncatemacro{\boundary}{\n - 1}

        \node[empty] (input) {\scriptsize x};
        \node[normalnode] (init-node) {\scriptsize label1};

        \foreach \twopow in {32, 16, 8} {

            \bridgedblock{\twopow-1};
            \foreach \name [evaluate=\name as \pred using int(\name - 1)] in {2,...,\boundary} {
                \bridgedblock{\twopow-\name};
                \path (\twopow-\pred-node2) edge (\twopow-\name-node1);
            }
            \bridgedblock{\twopow-last}
            \path (\twopow-\boundary-node2) edge (\twopow-last-node1);
        }

        \node[empty] (noboxnode) {\scriptsize noboxnode};
        \node[normalnode] (lastnode) {\scriptsize lastnode};
        \node[empty] (output) {\scriptsize};

        \path (input) edge (init-node);
        \path (init-node) edge (32-1-node1);
        \path (32-last-node2) edge (16-1-node1);
        \path (16-last-node2) edge (8-1-node1);
        \path (8-last-node2) edge (noboxnode);
        \path (noboxnode) edge (lastnode);
        \path (lastnode) edge (output);
    \end{tikzpicture}
}

\usepackage{caption, marginnote, adjustbox}

\begin{document}

\chapter{Chapter 1}

\marginnote{%
\parbox[t]{\marginparwidth}{\centering\adjustbox{width=\marginparwidth}{\insertpicture}
\captionsetup{format=plain, font =footnotesize}\captionof{figure}{A very very long data flow graph.}%
 }}%
\lipsum[1]
{\section{Section 1}}%

\lipsum

\section{Section 2}

\section{Section 3}

\section{Section 4}

\end{document} 

enter image description here

  • Since the seemingly less "hacky" solutions here made it work for me I stuck to them. Thanks for your answer anyway. – mackcmillion Apr 1 '16 at 16:06
2

I think that the problem is that the figures (with all the spaces for captions, etc.) does fit in a raw page, but not in the text height allocated space. I checked by adding \vspace*{-4cm} before the centering in the wrapfigure:

 \begin{wrapfigure}{O}{0.4\textwidth}
    \vspace*{-4cm}
    \centering
    \insertpicture
    \caption{A very very long data flow graph.}
\end{wrapfigure}

...and the result page is:

Output with negative vspace

and at a glance it seems that the graph will not fit (consider that it should fit below the chapter heading...). So I changed the graph definition (at the start) as:

\newcommand{\insertpicture}[1][1.0]{
    \begin{tikzpicture}[scale=#1,transform shape, node distance=0.55cm, start chain=going below, shorten >=1pt, ->]
...

and now I have, with:

\begin{wrapfigure}{O}{0.4\textwidth}
    \centering
    \insertpicture[0.8]
    \caption{A very very long data flow graph.}
\end{wrapfigure}

this result:

result scaling down

which I think it is more or less what you looked for.

  • Your answer in combination with @David Carlisle's made it work. Thanks! – mackcmillion Apr 1 '16 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.