2

Is it somehow possible to have different \captionsetup depending on the floating position a table ends up with?

In the following MWE I'd like to have \captionsetup{belowskip=0pt} automatically for all tables which end up to be placed at the top of a page in order to remove the space marked by the red arrow:

enter image description here

\documentclass{book}

\usepackage{graphicx}
\usepackage{lipsum}

\usepackage{caption}
\captionsetup*[table]{position=above, belowskip=\baselineskip}

\usepackage[showframe]{geometry}

\begin{document}

\lipsum[2]
\begin{table}[htbp]
\caption{test}
\end{table}
\lipsum[2-6]
\begin{table}[htbp]
%\captionsetup{belowskip=0pt}
\caption{test}
\end{table}
\lipsum[2]

\end{document}
9
  • 1
    the entire table is set before it is positioned so in general it's a bit tricky but you can do a multi-pass thing which records the typeset position on the previous run, or I have an answer somewhere that typesets all the versions and picks one to use as the float is positioned, I'll see if I can find it... Mar 8, 2018 at 17:28
  • @DavidCarlisle That looks very promising! Thanks for the link. I will test and report back (might take a bit, a lecture is about to start ...) Mar 8, 2018 at 17:32
  • If you can this space you also change the size of the table so the placement could perhaps change. Wouldn't it make more sense to set the value to 0 and to change \textfloatsep etc to change the spacing around the floats? Mar 8, 2018 at 17:32
  • @UlrikeFischer Already thought about this. I'm willing to compensate for this space somewhere else in the table, maybe at the bottom. I will also try your suggestion with \textfloatsep. Mar 8, 2018 at 17:35

1 Answer 1

1

The comment of @Ulrike Fischers comment put me on track to find a workaround. The basic idea is to modify \intextsep instead of trying to do this via the caption package.

A nice overview of the spaces around floats can be found at Remove space after figure and before text

\documentclass{book}

\usepackage{graphicx}
\usepackage{lipsum}

\usepackage{caption}
\captionsetup*[table]{position=above, 
belowskip=0pt,
}
\setlength{\intextsep}{\baselineskip}

\usepackage[showframe]{geometry}

\begin{document}

\lipsum[2]
\begin{table}[htbp]
\caption{test}
\centering
\includegraphics[width=1cm]{example-image}
\end{table}
\lipsum[2-6]
\begin{table}[t]
\caption{test}
\centering
\includegraphics[width=1cm]{example-image}
\end{table}
\lipsum[2]

\clearpage
\lipsum[2]
\begin{figure}[htbp]
\centering
\includegraphics[width=1cm]{example-image}
\caption{test}
\end{figure}
\lipsum[2-6]
\begin{figure}[t]
\centering
\includegraphics[width=1cm]{example-image}
\caption{test}
\end{figure}
\lipsum[2]

\end{document}
1
  • @UlrikeFischer In case you would like to add an answer of your own, I'll happily delete this one Mar 12, 2018 at 11:55

You must log in to answer this question.

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