5

As a vertical spacer between paragraphs in a book (see picture), I want to insert a small image that has a height of several lines (some definable number) and a definable amount of vertical space before and after it. The image should not mess with the rest of the vertical text alignment on that page. That is, the bottom should be flush and agree with preceding and succeeding pages.

Of course I could manually figure out the correct spacings by trial and error and add corresponding vertical spaces to get the bottom flush, but this is font/documentclass dependent. Also, problems arise when the image occurs at either the top or the bottom of the page, or when the preceding paragraph is just a few words long (see second image).

Example of image spacer, separating two paragraphs.

Wrong spacing when preceding paragraph is very short or when the image is place at top of page.

2 Answers 2

3

Define the height of the included image as a multiple of \baselineskip.

\newcommand\vspacer
  {\par
     {\centering
      \raisebox{-0.2\baselineskip}%
        {\includegraphics[height=3\baselineskip]{example-image}%
        }%
      \par
     }%
  }

According to the discussion in the comments, the lines of a page should get aligned with the corresponding lines of the other pages. Therefore one has to take care that space like \parskip and \lineskip do not stretch or shrink. This can be obtained by issuing the command \raggedbottom and by removing the stretch.

\raggedbottom
\lineskip0pt
\parskip0pt

In the example below I load the package showframe to mark the border of the text area.

enter image description here enter image description here enter image description here

\documentclass[12pt]{scrbook}
\usepackage{graphicx}
\usepackage{blindtext}
\usepackage{showframe}
\newcommand\vspacer
  {\par
     {\centering
      \raisebox{-0.2\baselineskip}%
        {\includegraphics[height=3\baselineskip]{example-image}%
        }%
      \par
     }%
  }
\raggedbottom
\lineskip0pt
\parskip0pt
\begin{document}
\Blindtext
\vspacer
\Blindtext
\vspacer
\Blindtext
\vspacer
\Blindtext
\blindtext
\end{document}
10
  • This works fine. Also adding extra vspace before and/or after the spacer seems to be no problem. However, for some reason your method does not work if one uses the "oneside" option, for example, with \documentclass[12pt,d5paper,oneside]{scrbook}. Any suggestions?
    – Muk
    Commented Jan 3, 2017 at 19:13
  • @Muk If I change the first line of my sample document to \documentclass[12pt,d5paper,oneside]{scrbook}, then I only get the warning that the option d5paper hasn't been used, but otherwise the document stays the same (except for the margins). There must be something else in your document that causes the problem.
    – gernot
    Commented Jan 3, 2017 at 19:18
  • I used your exact same code, but \flushbottom was missing. Thanks a lot.
    – Muk
    Commented Jan 3, 2017 at 19:30
  • After all, it seems your solutions does not work all the time. If I add in your example more spacers and blindtext (\Blindtext \vspacer), say eight of them, you can see the alignment problems, especially if the spacer image appears at the top of the page.
    – Muk
    Commented Jan 8, 2017 at 19:25
  • @Muk What exactly do understand by alignment problem? If \flushbottom is activated (which is the default for the book class), then TeX will fill the complete page (provided you don't prevent it by too little stretchable space). Add the line \usepackage{showframe} to your preamble and check yourself. Or do you want to have all lines of a page aligned with the corresponding lines of all the other pages?
    – gernot
    Commented Jan 9, 2017 at 15:21
1

I would add some glue to the space before and after the spacer. This would allow them to stretch/shrink as needed in order to maintain a \flushbottom:

enter image description here

\documentclass{book}

\usepackage{graphicx,lipsum}

\newcommand{\insertseparator}{%
  \par
  \vspace{.2\baselineskip plus .2\baselineskip minus .2\baselineskip}% Space above
  \noindent
  \makebox[\linewidth]{\includegraphics[height=3\baselineskip]{example-image}}%
  \par
  \vspace{.2\baselineskip plus .2\baselineskip minus .2\baselineskip}% Space below
}

\begin{document}

\lipsum[1]

\insertseparator

\lipsum[2-14]

\insertseparator

\lipsum[15-29]

\insertseparator

\lipsum[30-45]

\insertseparator

\lipsum[46-50]

\end{document}

You may have to play around with suitable values for plus and/or minus. I've just used part of a \baselineskip.

You must log in to answer this question.

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