3

I am trying to insert insets of commutative diagrams into my tex, using wrapfigure and tikz. The first commutative diagram (inside a wrapfigure environment) appears as it should, but the second commutative diagram (inside its own wrapfigure) appears much lower than it should, in a later paragraph. Here is a minimum-working-example:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,arrows}
\usepackage{wrapfig}
\begin{document}

%+Title
\title{Article Title}
\author{Author}
\date{\today}
\maketitle
%-Title

%+Abstract
\begin{abstract}
test
\end{abstract}
%-Abstract


\section{test}
\begin{wrapfigure}[5]{r}{0.3\textwidth}
\vspace{-18pt}
\hspace{-0pt}
\begin{tikzpicture}[description/.style={fill=white,inner sep=0pt}]
\matrix (m) [matrix of math nodes, row sep=3em,
column sep=2.5em, text height=1.5ex, text depth=0.25ex]
{ M & & N \\
& D & \\ };
%\draw[double,double distance=5pt] (m-1-1) – (m-1-3);
\path[<->]
(m-1-1) edge node[description] {$ f $} (m-1-3)
edge node[description] {$ \Phi $} (m-2-2)
(m-1-3) edge node[description] {$ \Psi $} (m-2-2);
\end{tikzpicture}
\end{wrapfigure}
one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one\\
\begin{wrapfigure}[5]{r}{0.3\textwidth}
\vspace{-18pt}
\hspace{-0pt}
\begin{tikzpicture}[description/.style={fill=white,inner sep=0pt}]
\matrix (m) [matrix of math nodes, row sep=3em,
column sep=2.5em, text height=1.5ex, text depth=0.25ex]
{ M & & N \\
& D & \\ };
%\draw[double,double distance=5pt] (m-1-1) – (m-1-3);
\path[<->]
(m-1-1) edge node[description] {$ f $} (m-1-3)
edge node[description] {$ \Phi $} (m-2-2)
(m-1-3) edge node[description] {$ \Psi $} (m-2-2);
\end{tikzpicture}
\end{wrapfigure}two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two


\end{document}

The second diagram appears below the "two" section, rather than to the right of it as I intend. What am I doing wrong?

`

2
  • 1
    insert a line break before your second wrapfigure
    – cmhughes
    Commented Jun 28, 2014 at 23:59
  • @cmhughes - Thanks! that solved it. If you write this comment as an answer (with perhaps an explanation to this "black magic" - I didn't know line breaks affect wrapfigure environments), I'll gladly accept.
    – olamundo
    Commented Jun 29, 2014 at 0:08

1 Answer 1

1

You need to place either a blank line or a \par command before the second wrapfigure environment, so that a new paragraph is begun.

The wrapfigure environment operates on paragraphs of text; without the blank line (or \par command), the wrapfig assumes that you are still within the first paragraph of text.

Here's the complete code to play with

% arara: pdflatex
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,arrows}
\usepackage{wrapfig}
\begin{document}

%+Title
\title{Article Title}
\author{Author}
\date{\today}
\maketitle
%-Title

%+Abstract
\begin{abstract}
test
\end{abstract}
%-Abstract


\section{test}
\begin{wrapfigure}[5]{r}{0.3\textwidth}
\vspace{-18pt}
\hspace{-0pt}
\begin{tikzpicture}[description/.style={fill=white,inner sep=0pt}]
\matrix (m) [matrix of math nodes, row sep=3em,
column sep=2.5em, text height=1.5ex, text depth=0.25ex]
{ M & & N \\
& D & \\ };
%\draw[double,double distance=5pt] (m-1-1) – (m-1-3);
\path[<->]
(m-1-1) edge node[description] {$ f $} (m-1-3)
edge node[description] {$ \Phi $} (m-2-2)
(m-1-3) edge node[description] {$ \Psi $} (m-2-2);
\end{tikzpicture}
\end{wrapfigure}
one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one\\

\begin{wrapfigure}[5]{r}{0.3\textwidth}
\vspace{-18pt}
\hspace{-0pt}
\begin{tikzpicture}[description/.style={fill=white,inner sep=0pt}]
\matrix (m) [matrix of math nodes, row sep=3em,
column sep=2.5em, text height=1.5ex, text depth=0.25ex]
{ M & & N \\
& D & \\ };
%\draw[double,double distance=5pt] (m-1-1) – (m-1-3);
\path[<->]
(m-1-1) edge node[description] {$ f $} (m-1-3)
edge node[description] {$ \Phi $} (m-2-2)
(m-1-3) edge node[description] {$ \Psi $} (m-2-2);
\end{tikzpicture}
\end{wrapfigure}two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two


\end{document}
2
  • Thanks. I read answers from nearly 30 persons, searched 90mins and none of them worked.. Now I found this answer and it works nice using tikz.
    – user49121
    Commented Jan 9, 2015 at 22:24
  • @TimS. awesome, glad it helped :)
    – cmhughes
    Commented Jan 9, 2015 at 23:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .