My goal is simple to accomplish in most word processing programs and it really should work here. I want at the top of a section, a photo on the right of the person the section is about, and I would like the text to wrap around that photo. Seems pretty easy, right?
I am using \wrapfig for this, but there are some pretty odd side effects and instead of just wrapping nicely around the picture, seems to effect every paragraph in the following section. Sample is at the bottom. Here is what it produces:
And the following page is:
As you can see:
(1) there is a gap between the top of the section header and the top of the photo. I would like the photo to start at the same line that starts the section, and not some 1/4 lower.
(2) the wrapping overwrites the caption
(3) this block of "wrapping" seems to repeat for every paragraph of the section.
(4) there are even worse problems if the photo is too close to the bottom of the page, so I am manually putting in page breaks for those cases.
Here is the MWE:
\documentclass[paper=7in:10in,11pt,pagesize=pdftex,openright,headings=twolinechapter,chapterprefix=true]{scrbook}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{makeidx}
\usepackage{fontspec}
\usepackage{needspace}
\usepackage{longtable}
\usepackage{framed}
\usepackage{enumitem}
\usepackage{setspace}
\usepackage{tcolorbox}
\usepackage{url}
\usepackage{showframe}
\usepackage{lineno}
\usepackage[natbibapa]{apacite}
\bibliographystyle{apacite}
%\usepackage{natbib}
%\usepackage[style=authoryear,sorting=ynt]{biblatex}
%\DefineBibliographyStrings{english}{urlseen = {Accessed\addcolon}}
\setmainfont[Ligatures={Common,TeX}, Numbers={OldStyle}]{Palatino Linotype}
%\KOMAoptions{DIV=last} % goofy KOMA requirement whenever you change leading
\addtokomafont{footnote}{\footnotesize\fontspec[Ligatures=TeX]{Alegreya Sans}}
\deffootnote{1.5em}{1em}{% modified example from page 83
\makebox[1.5em][l]{\textsuperscript{\thefootnotemark}}}
\definecolor{skyblue}{rgb}{0.53, 0.81, 0.92}
\definecolor{shadecolor}{rgb}{0.95, 0.95, 0.95}
\makeindex
%page is 7 x 10. With these margins the printed area
%is 5.75 inches by 9 inches.
\usepackage[inner=0.75in,outer=0.50in,top=0.75in, bottom=0.75in, footnotesep=.3in, footskip=.4in]{geometry}
\renewcommand*\chapterheadstartvskip{\vspace*{.1\textheight}}
\renewcommand*\chapterheadendvskip{\vspace*{.1\textheight}}
\addtokomafont{chapter}{\fontspec[Ligatures=TeX]{Alegreya Sans SC Light}}
\addtokomafont{chapterprefix}{\fontspec[Ligatures=TeX]{Alegreya Sans SC Light}\Huge}
\addtokomafont{chapterprefix}{\raggedleft}
\renewcommand*{\chapterformat}{%
\mbox{\scalebox{1}{\chapappifchapterprefix{\nobreakspace}}%
\scalebox{4}{\color{gray}\thechapter}\enskip}}
%Page size settings
\pdfpagewidth=\paperwidth
\pdfpageheight=\paperheight
\widowpenalty10000
\clubpenalty10000
\hyphenation{}
\addtokomafont{section}{\raggedright}
\addtokomafont{subsection}{\raggedright}
\setcounter{secnumdepth}{0}
\setlength{\emergencystretch}{15pt}
\newenvironment{glossarylist}%
{\begin{list}{}{\setlength\labelwidth{0pt}%
\setlength\itemindent{-\leftmargin}%
\let\makelabel\descriptionlabel}}%
{\end{list}}
\newenvironment{centerTable}[1][Examples]%
{\begin{longtable}{| p{2.5in} |} \hline \rowcolor{lightgray} \emph{#1} \\ \hline }%
{\end{longtable}}
\newcommand{\partfrontpage}[1]{%
\cleardoublepage\vspace*{2.0in}\thispagestyle{empty}%
\begin{center}%
\noindent\fontspec[Ligatures=TeX]{Alegreya Sans SC Light}%
\doublespacing\Huge #1%
\end{center}}
\newcommand{\centerLine}[1]{ #1 \\ \hline }
%this allows graphics from one folder to be included in one style
%but when building hypertext it includes a different set of graphics from
%a different folder
\newcommand{\bookcoverimage}[1]{\noindent\includegraphics[width=2in]{img/#1}}
\newcommand{\simpleimage}[2]{%
\begin{figure}[!ht]%
%\vspace{10pt}%
\begin{center}%
\noindent\includegraphics[width=5in]{img/#1}\\%
\emph{#2}%
\end{center}%
\end{figure}%
}
\newcommand{\sizeimage}[3]{%
\begin{figure}[!ht]%
%\vspace{10pt}%
\begin{center}%
\noindent\includegraphics[width=#3in]{img/#1}\\%
\emph{#2}%
\end{center}%
\end{figure}%
}
%\intextsep = 0pt
\newcommand{\rightimage}[3]{%
\begin{wrapfigure}{r}{#3in}%
\noindent\includegraphics[width=#3in]{img/#1}\\%
\centering\emph{#2}%
\end{wrapfigure}%
}
\newcommand{\narrowimage}[1]{\noindent\includegraphics[width=2in]{img/#1}}
\newcommand{\citePlain}[1]{\footnote{\citep{#1}}}
\newcommand{\citePlainP}[2]{\footnote{\citep[#2]{#1}}}
\newcommand{\citeSpecial}[1]{\footnotetext{\citep{#1}}}
\newcommand{\citeSpecialP}[2]{\footnotetext{\citep[#2]{#1}}}
%control whether extra vertical space is distributed between paragraphs
%either raggedbottom or flushbottom
\raggedbottom
\usepackage{tcolorbox}
\newtcolorbox{boxedQuote}{colback=gray!30,boxrule=0pt,arc=0pt,boxsep=2pt,left=2pt,right=2pt,leftrule=1pt}
\begin{document}
Dave Campbell Purcell, second son of Margaret and David Purcell, always maintained a strong interest in our David family history---especially in his later life. In the 1960s he and his wife Elizabeth (``Betty''), made at least one trip from their home in Maine to visit their cousins in the Wallace, Gulf Shore, Fox Harbour areas of northern Nova Scotia. I have several letters that Dave had written to my mother during those years. In later years, I corresponded with him on all things relating to the David family. He was particularly interested in any effort to learn more about the early family members who came to North America from Europe. Several times Mary Lee and I visited with Dave and Betty at their home in Maine. They were always charming and welcoming – Betty interested to know about our son and daughter, and Dave, his desk covered with notes, charts, and printouts, eager to discuss any new discoveries on the family history front. Dave died January 8th, 2004 at the age of eighty-eight and Betty on July 10, 2014.
\rightimage{ch19-DavidBettyPurcell.jpg}{Dave \& Betty Purcell ca 1998}{2}
\section{Dave Campbell Purcell}
Dave Campbell Purcell, second son of Margaret and David Purcell, always maintained a strong interest in our David family history---especially in his later life. In the 1960s he and his wife Elizabeth (``Betty''), made at least one trip from their home in Maine to visit their cousins in the Wallace, Gulf Shore, Fox Harbour areas of northern Nova Scotia. I have several letters that Dave had written to my mother during those years. In later years, I corresponded with him on all things relating to the David family. He was particularly interested in any effort to learn more about the early family members who came to North America from Europe. Several times Mary Lee and I visited with Dave and Betty at their home in Maine. They were always charming and welcoming – Betty interested to know about our son and daughter, and Dave, his desk covered with notes, charts, and printouts, eager to discuss any new discoveries on the family history front. Dave died January 8th, 2004 at the age of eighty-eight and Betty on July 10, 2014.
Dave and Betty Purcell had three children: David, Joanne and Elizabeth. In early December, 2017, I was able to establish contact with Joanne and her husband Bob Flynn. They live in Vermont. Throughout the spring of 2018 Joanne and I got acquainted through emails and phone chats. At one point I asked her if she had some special memories of her father that she could share with me. This is a part of her reply:
My father and I were very close; I have so many memories: spending endless house at his elbow in his workshop watching him explore, create, take apart, put together. Electrical . . . mechanical, didn't matter, he could fix anything---all the while teaching, explaining. We once even took apart a television set so he could describe how it worked! I can still envision the large picture tube, something that doesn't even exist anymore. I remember his infectious laugh, his wonderful sense of humour . . . and his pranks . . . he loved to play harmless pranks. One of the best was the Halloween he put a vacuum cleaner under our porch so that when the Trick or Treaters stepped up to the door, the machine would turn on. Only a few ran away!
Dave Campbell Purcell, second son of Margaret and David Purcell, always maintained a strong interest in our David family history---especially in his later life. In the 1960s he and his wife Elizabeth (``Betty''), made at least one trip from their home in Maine to visit their cousins in the Wallace, Gulf Shore, Fox Harbour areas of northern Nova Scotia. I have several letters that Dave had written to my mother during those years. In later years, I corresponded with him on all things relating to the David family. He was particularly interested in any effort to learn more about the early family members who came to North America from Europe. Several times Mary Lee and I visited with Dave and Betty at their home in Maine. They were always charming and welcoming – Betty interested to know about our son and daughter, and Dave, his desk covered with notes, charts, and printouts, eager to discuss any new discoveries on the family history front. Dave died January 8th, 2004 at the age of eighty-eight and Betty on July 10, 2014.
Dave and Betty Purcell had three children: David, Joanne and Elizabeth. In early December, 2017, I was able to establish contact with Joanne and her husband Bob Flynn. They live in Vermont. Throughout the spring of 2018 Joanne and I got acquainted through emails and phone chats. At one point I asked her if she had some special memories of her father that she could share with me. This is a part of her reply:
My father and I were very close; I have so many memories: spending endless house at his elbow in his workshop watching him explore, create, take apart, put together. Electrical . . . mechanical, didn't matter, he could fix anything---all the while teaching, explaining. We once even took apart a television set so he could describe how it worked! I can still envision the large picture tube, something that doesn't even exist anymore. I remember his infectious laugh, his wonderful sense of humour . . . and his pranks . . . he loved to play harmless pranks. One of the best was the Halloween he put a vacuum cleaner under our porch so that when the Trick or Treaters stepped up to the door, the machine would turn on. Only a few ran away!
\end{document}
Previously i was given the answer to change \intextsep
but changing that messes up figures in the document.
Step Two
My first sample had some problems that could be fixed:
(A) The \\
should be replaced with \par
to avoid problems with the caption text
(B) An \mbox
must be added after the \wrapfig
in order to avoid causing the wrapping in every paragraph in the section. I don't have a conceptual understanding of why this happens, but I understand it is because the section head causes the following text to be grouped? The \mbox
somehow separates the \wrapfig
from the section.
(C) One must control the length of wrap space manually. I am now resigned to setting this manually for every one of 48 images in the book. Would be nice if it could calculate this from the image size itself, however for now if I can get it to work, I can set the box size manually on 48 images.
(D) The top of the box was not quite right with the section, so the text in section (the header of the section particularly) can be pulled up on the page by using \vspace*{-1.2\baselineskip}
to get the top approximately at the top of the image.
I sometimes need image next to a header, and sometimes in the middle of paragraphs.
Two remaining problems:
(1) The section head with image is spaced a bit differently. Looks like if I put a vspace
before the image, I can get it lower on the page, and then I can adjust the other negative vspace
to line that up.
(2) I made a separate command for placing images in the text (not at the section head). If the \mbox
was in there, it left gap of about one line. So this new command eliminates the \mbox
. I used a vspace{-1.0\intextsep}
to cancel out the space on top, and then of course using the manual sizing to control the space below.
Step Three
It turns out there is one other situation to consider, and that is when the section header appears at the top of a page, and this will happen any time there is not enough room on the previous page for the picture.
The \mbox
approach does not work because in the above situation that \mbox
causes extra white space at the top of the page which is not needed.
The better approach is to place the image into the paragraph after the section header, but use vspace to raise the image up to the height of the header. Then, because we are manually controlling the number of lines to shorten, we can make the space close in the right place.
The two commands to define are:
\newcommand{\rightimageH}[4][]{% for use at sections head
\begin{wrapfigure}[#1]{r}{#4in}%
\vspace*{-3.1\baselineskip}%
\noindent\includegraphics[width=#4in]{example-image-1x1.png}\par%
\centering\emph{#3}%
\end{wrapfigure}%
}
\newcommand{\rightimage}[4][]{% for use in body text
\begin{wrapfigure}[#1]{r}{#4in}%
\vspace*{-1.0\intextsep}%
\noindent\includegraphics[width=#4in]{example-image-1x1.png}\par%
\centering\emph{#3}%
\end{wrapfigure}%
}
This is then used with a section header like this:
\section{Dave Campbell Purcell}
\rightimageH[10]{ch19-DavidBettyPurcell.jpg}{Dave \& Betty Purcell ca 1998}{2}
Dave Campbell Purcell, second son of Margaret ...
Note that 10 lines are reserved in this case, but if you are putting this directly into the text (no header) then it goes like this with 12 lines shortened:
\rightimage[12]{ch19-DavidBettyPurcell.jpg}{Dave \& Betty Purcell ca 1998}{2}
Dave Campbell Purcell, second son of Margaret and David ...
With these I am successfully able to get the following tight wrapping around pictures on the right of the page:
insbox
plain TeX macro package, which defines an\InsertBoxR
command. You don't have to specify the width of the inserted box, and have only to possibly specify (as an optional argument) the number of supplementary shorter lines in case TeX makes a wrong calculation of the required number of shorter lines.\\
which you can delete. For the space at the top you can add\vepace{-\baselineskip}
before the image.But it is rather hard to proivide a tested answer if you provide no code.\intextsep
to 0pt is unlikley to be the correct solution but as noted in the answer posted without any code it is hard to guess why you are getting the space, please add an example to the question, usingexample-image-1x1.png
as the image as in the answer below.Louise
appears where it does. Exactly as you specified. You want the caption to be a new paragraph so leave a blank line before\centering