4

I am typesetting an illustrated book, and the author pointed at the pictures seemint to have a smaller headheight. I think he is right and I am wondering why.

Here is my MWE:

\documentclass{scrbook}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{graphicx,float}
\usepackage{lipsum}

\begin{document}
\lipsum[3]

\newpage

\begin{figure}[t]
\textbf{\framebox[70mm][r]{Example: headsep smaller }}
\end{figure}

\null
\vfill

\end{document}

And here is an image, that hopefully shows the problem:

headsep_smaller_above_floats

Any ideas?

5
  • 1
    Don't compare with normal text. Use a framebox instead if the \lipsum. Jul 12 '15 at 20:35
  • Thanks for the comment, but why not? Is it bad typography to have the pictures at the same vertical position as the text?
    – michael
    Jul 12 '15 at 20:52
  • 1
    Try it out and compare the positions. A framebox has a rather large height and would change the position of normal text too. Jul 12 '15 at 21:02
  • if you want to see replace \lipsum[3] by \fboxsep=0pt \textbf{\framebox[70mm][r]{Example: headsep smaller }} and add showframe package
    – touhami
    Jul 12 '15 at 21:15
  • Note that this ensures that, for a double-page spread, the lines of text on left and right pages will be aligned. Or, rather, it is a necessary though not sufficient condition for their alignment. If the top of box aligned with the top of the letters, this would not be the case.
    – cfr
    Jul 12 '15 at 21:55
5

I see nothing strange:

\documentclass{scrbook}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{graphicx,float}
\usepackage{lipsum}

\usepackage{fancyhdr}
\pagestyle{fancy} % just to show the head sep

\begin{document}
\makebox[0pt][l]{\vrule height0pt depth0.2pt width 30cm}%
\lipsum[3]

\newpage

\begin{figure}[t]
\textbf{\framebox[70mm][r]{%
  \makebox[0pt][r]{\vrule height0pt depth0.2pt width 30cm}%
  Example: headsep smaller }}
\end{figure}

\null
\vfill

\end{document}

The two hairlines are at the same level, and the same can be said about the top rules produced by fancyhdr (used just by way of example).

enter image description here

What's happening, really?

The normal pages are subject to a feature called \topskip: the first baseline will be at \topskip distance from the upper edge of the text block. This doesn't happen with a float, where the first line will be flush with the upper edge of the allotted space.

A more significant example would be

\documentclass{scrbook}

\usepackage{lipsum}
\usepackage{showframe}

\begin{document}

\lipsum[3]

\newpage

\begin{figure}[t]
  Nulla malesuada porttitor
\end{figure}

\null
\vfill

\end{document}

that would clearly show the situation.

I don't think this is a problem with floats, because they are a separate part and follow different rules.

If this is a concern, add

\vrule height\topskip width 0pt

to the first line.

5
  • can you try with just \makebox[0pt][r]{\vrule height0pt depth0.2pt width 30cm} as text and as object in figure?
    – touhami
    Jul 12 '15 at 22:29
  • @touhami Apples and oranges.
    – egreg
    Jul 12 '15 at 22:44
  • No I don't think so, with this you'll ses something strange (may be)
    – touhami
    Jul 12 '15 at 22:49
  • Thank you egreg! I compiled both examples and learned a lot (as always with tex.sx) – with "add ... to the first line" you meant: first line inside the figure?
    – michael
    Jul 15 '15 at 19:20
  • As I already pointed ot, thank you very much, egreg. Yours as well as @Gustavos Mezzettis commands don't work for me at the moment. That may be because of my document, it's rather complex, so it will take some time to test it. Maybe I will figure out how to use the commands, then I will report here.
    – michael
    Jul 21 '15 at 20:53
1

This is the command I usually employ to cope with this situation:

\newcommand*\cleantop{%
    \dimen@ \baselineskip
    \advance \dimen@ -\topskip
    \prevdepth \dimen@
}

After this definition, I use \cleantop at the beggining of the floating environment, as I show in the following MWE:

\documentclass{scrbook}

\usepackage{lipsum}
\usepackage{showframe}

\makeatletter
\newcommand*\cleantop{%
    \dimen@ \baselineskip
    \advance \dimen@ -\topskip
    \prevdepth \dimen@
}
\makeatother

\begin{document}

\lipsum[3]

\newpage

\begin{figure}[t]
    \cleantop
    Nulla malesuada porttitor
\end{figure}

\null
\vfill

\end{document}

Essentially the same as egreg’s suggestion.

1
  • As @egreg has already explained, the first box contributed to a page has \topskip glue above it, so that its baseline lies in a predetermined position. But this glue is not added to the first line of an “internal” box, like the box into which a figure is set. The \cleantop command emulates the \topskip glue in such “internal” boxes. Its advantage over egreg’s \vrule is that it is somewhat easier to define a customized figure environment using this \cleantop command than using \vrule.
    – GuM
    Jul 12 '15 at 23:39

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.