1

I would like to patch my [H] floats with some vertical space as it appears inconsistent with [h] and other type floats. I am using KOMAscript

Is there a good way to put code before/after the environment, only if [H] arg is passed? I can achieve the affect by manually putting \vspace{}, but obviously I'd rather not every time.

I would also like to avoid creating a new environment; I feel that having the native float declarations will make my .tex files usable/transferrable with other formats.

Alternatively, if you know a good way to make the spacing consistent, that would help.

EDIT: Adding a MWE

\documentclass[parskip=full,captions=tableheading]{scrartcl}

\usepackage{mwe}

\usepackage{float}

\usepackage[tableposition=top,labelfont=bf,skip=0pt]{caption}
\setlength\belowcaptionskip{0pt}
\setlength\abovecaptionskip{0pt}

\setlength{\intextsep}{\baselineskip}


\newcommand{\blah}{Here are some random words. Blah, blah blah blah blah blah blah blah.}


\begin{document}

    \blah

    \begin{figure}[h]
        \centering
        \noindent\includegraphics[height=5cm]{example-image-b} 
        \caption{h type figure, see the space below}
    \end{figure}

    \blah

    \begin{figure}[H]
        \centering
        \noindent\includegraphics[height=5cm]{example-image-b} 
        \caption{H type figure, see the extra space below}
    \end{figure}

    \blah

\end{document}


  • [H] should be using \intextsep the same as h floats. – David Carlisle Jan 28 at 18:52
  • @DavidCarlisle, there is definitely more space under the H. I posted a MWE. – likethevegetable Jan 28 at 19:03
  • 1
    Congratulations -- You've discovered yet another reason why the [H] location specifier should be avoided entirely. Seriously: don't use it; use [ht!] instead. – Mico Jan 28 at 19:30
  • 1
    @likethevegetable - The belief that [H] will give you something better than [ht!] is an illusion, a mirage. If there's enough space left on the page to place the float, then [H] and [ht!] produce the exact same outcome. And if there's not enough space left on the page to place the float, then [H] and [ht!] will both place the page at the top of the next page. (Where else should the float go?!) The difference is that [H] will create a huge, unsightly gap at the bottom of the page that precedes the float, whereas [ht!] will not. – Mico Jan 28 at 20:32
  • 2
    In addition to what Mico says, the only reason to use figure environment is to specify it can float, if you want an image to be part of the main document flow just use \includegraphics directly. marking a float then adding additional markup to make it non float makes no sense. [H] was my idea, but I was younger then, and wrong. – David Carlisle Jan 28 at 21:04
3

You could try to patch the end command to add a negative \parskip:

\documentclass[parskip=full,captions=tableheading]{scrartcl}

\usepackage{mwe}

\usepackage{float}
\usepackage{etoolbox}
\makeatletter
\patchcmd\float@endH{\relax}{\vskip-\parskip\relax}{}{\fail}
\makeatother

\usepackage[tableposition=top,labelfont=bf,skip=0pt]{caption}
\setlength\belowcaptionskip{0pt}
\setlength\abovecaptionskip{0pt}

\setlength{\intextsep}{\baselineskip}


\newcommand{\blah}{Here are some random words. Blah, blah blah blah blah blah blah blah.}


\begin{document}

    \blah

    \begin{figure}[h]
        \centering
        \noindent\includegraphics[height=5cm]{example-image-b}
        \caption{h type figure, see the space below}
    \end{figure}

    \blah

    \begin{figure}[H]
        \centering
        \noindent\includegraphics[height=5cm]{example-image-b}
        \caption{H type figure, see the extra space below}
    \end{figure}

    \blah

\end{document}
| improve this answer | |
  • Thank you; I believe this is exactly what I need. I tested it out and it seems to produce what I desire. If you don't mind, can you please explain the @endH ? And if you really don't mind, if you broke down that particular patch entirely and explained it, I think I would learn a lot from it. Thanks regardless. – likethevegetable Jan 28 at 20:10
  • And another thing; if I was using floatrow, how would I do this? – likethevegetable Jan 28 at 20:14
  • 1
    Isn't noindent (before \includegraphics) superfluous? – Zarko Jan 28 at 20:28
  • @Zarko probably... hah. I'm pretty sure. I just copied that because I needed a MWE image. – likethevegetable Jan 28 at 21:12

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.