I'm making a document using the memoir theme. In my document, I wish to have images floated to the left or the right at times.
I've got this working reasonably well:
\documentclass[twoside]{memoir}
\usepackage[papersize={8.5in,11in}, vmargin=0.5in, outer=1in, inner=0.5in, includehead, includefoot]{geometry}
\usepackage{color}
\usepackage{fontspec}
\usepackage{newunicodechar}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\usepackage[none]{hyphenat}
\usepackage{graphicx}
\usepackage{wrapfig}
\graphicspath{ {images/} }
\makeatletter
\newcommand\floatingimage[4]{
\begin{wrapfigure}{#3}{0.25\textwidth}%
\vspace{-20pt}%
\begin{center}%
\includegraphics[width=0.25\textwidth]{#1}%
\end{center}%
\vspace{-15pt}%
\legend{#4}%
\vspace{-15pt}%
\end{wrapfigure}%
}
% Remove 'Figure 1' text
\patchcmd{\legend}%Cmd
{\normalsize}%Search
{\small\bfseries\raggedright}%Replace
{}%Success
{}%Fail
% Custom section heading
\newcommand{\beginsection}[1]{%
\let\@section@title@\relax
\normalfont\large\bfseries #1
\normalfont\normalsize
\par
\vspace{0.5pt} % Required for vertical alignment, not quite sure why it's necessary
\gdef\@section@title@{#1}
}
\makeatother
\setlength{\parindent}{0pt}%
\nonzeroparskip
\begin{document}
\chapterstyle{scp}
\chapter{Example}
\floatingimage{800placeholder}{800}{R}{Figure A}
\beginsection{Section 1}
\lipsum[1-1]
\beginsection{Section 2}
\lipsum[2-2]
\floatingimage{150placeholder}{150}{L}{Figure B}
\lipsum[3-3]
\beginsection{Section 3}
\lipsum[4-4]
\end{document}
The only thing is, I don't like the way the 'Section 3' heading is pushed inwards. I'd like instead for headings to appear after the floated element, at the start of a line. Ideally I would like for this behaviour to only apply when the float is on the left, as floats on the right don't push the titles.
In CSS I could accomplish this using h3 { clear: left; }
. What's the LaTeX equivalent?
I did some searching and found \FloatBarrier in the placeins
package, but this didn't change the output at all. Here's how I tried to use it.
\documentclass[twoside]{memoir}
\usepackage[papersize={8.5in,11in}, vmargin=0.5in, outer=1in, inner=0.5in, includehead, includefoot]{geometry}
\usepackage{color}
\usepackage{fontspec}
\usepackage{newunicodechar}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\usepackage[none]{hyphenat}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{placeins}
\graphicspath{ {images/} }
\makeatletter
\newcommand\floatingimage[4]{
\begin{wrapfigure}{#3}{0.25\textwidth}%
\vspace{-20pt}%
\begin{center}%
\includegraphics[width=0.25\textwidth]{#1}%
\end{center}%
\vspace{-15pt}%
\legend{#4}%
\vspace{-15pt}%
\end{wrapfigure}%
}
% Remove 'Figure 1' text
\patchcmd{\legend}%Cmd
{\normalsize}%Search
{\small\bfseries\raggedright}%Replace
{}%Success
{}%Fail
% Custom section heading
\newcommand{\beginsection}[1]{%
\let\@section@title@\relax
\FloatBarrier
\normalfont\large\bfseries #1
\normalfont\normalsize
\par
\vspace{0.5pt} % Required for vertical alignment, not quite sure why it's necessary
\gdef\@section@title@{#1}
}
\makeatother
\setlength{\parindent}{0pt}%
\nonzeroparskip
\begin{document}
\chapterstyle{scp}
\chapter{Example}
\floatingimage{800placeholder}{800}{R}{Figure A}
\beginsection{Section 1}
\lipsum[1-1]
\beginsection{Section 2}
\lipsum[2-2]
\floatingimage{150placeholder}{150}{L}{Figure B}
\lipsum[3-3]
\beginsection{Section 3}
\lipsum[4-4]
\end{document}
(Not going to attach a screenshot as it looks identical to the one above)
How can I achieve the effect I'm after?
EDIT: I found this related question but I can't get their solution working for me.
%
to lots of lines where not needed but\newcommand\floatingimage[4]{
needs onecenter
just use\centering
, which adds no vertical space