4

How can I control the vertical spacing of the parbox relative to the image?

\documentclass[12pt,a4paper]{article}
\usepackage[top=1in, bottom=1in, inner=1in, outer=1in]{geometry}
\usepackage[onehalfspacing]{setspace}
\usepackage[utf8]{inputenc}
\usepackage{ngerman}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{caption}
\captionsetup[figure]{font=normalsize,skip=10pt}
\usepackage[flushleft]{threeparttable}

\begin{document}

        \begin{figure}[!htb]
            \centering
            \caption{}
            \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{untitled.png}
            \parbox{\textwidth}{\footnotesize Hallo}
        \end{figure}

\end{document}
S. Ming
  • 171
  • By vertical spacing, are you referring to the space between the image and the \parbox? – Werner Sep 23 '16 at 00:20
  • 1
    parboxes and images are positioned like letters you have includegraphics followed by parbox with one word-space in between, but as they are full width they are on separate lines. It is better to put them in separate paragraphs so leave a blank line between, you can insert \vspace{2cm} or whatever you need after the blank line brefore the parbox – David Carlisle Sep 23 '16 at 00:20
  • @werner yes, I was referring to the space between the image and the \parbox – S. Ming Sep 23 '16 at 00:30

1 Answers1

4

Your current image is set to the width of the text - \textwidth. In a landscape image this will be fixed, with the height adjusted to match. I assume this is a more preferred resizing as an image of height=\textheight will cause overfull \vbox issues in the output since you also include a \caption.

Based on the above assumption and the fact that you're setting a \parbox of width \textwidth, you can insert any \vspace{<len>} between the two components - image and paragraph - to obtain a gap of desired choice:

enter image description here

\documentclass{article}

\usepackage{graphicx}

\begin{document}

\begin{figure}[!htb]
  {\centering \caption{Figure caption}}
  \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{example-image}

  \vspace{5\baselineskip}% Or whatever length you want

  {\footnotesize \strut
  Some text
  \strut\par}
\end{figure}

\end{document}

Note the following requirements/changes:

  • \centering is only applied to the \caption, as the other components are set to occupy a block of width \textwidth;

  • a blank line between the image and the following paragraph to ensure you're in vertical mode. This allows for the proper placement of the \vspace;

  • Setting of the paragraph with additional \struts as well as an ending \par to obtain a proper baseline representation (\parbox are known to have visual issues regarding this).

Werner
  • 603,163
  • Is there a way to set the note according to width of the image? So that it doesn't cover the textwidth. I'm using the code you wrote in your answer. – S. Ming Oct 06 '16 at 01:10
  • @S.Ming: So if your image ends up having a width < \textwidth, you want to set the note at the bottom to also be in a box that has the same < \textwidth width? – Werner Oct 06 '16 at 01:13
  • Yes, so that the width of the note equals the width of the image. I know how to do it with \parbox but not with the code you wrote in your answer. – S. Ming Oct 06 '16 at 01:20
  • 1
    @S.Ming: In your preamble, add \newsavebox{\imagebox}, then in the figure environment you can use \savebox{\imagebox}{\includegraphics[..]{...}}\usebox{\imagebox}. This way you store the image inside a box (and then set that box immediately) of which one can measure the width. This allows you to set the note inside a \parbox{\wd\imagebox}{..}. – Werner Oct 06 '16 at 01:48