Search code examples
latexpdflatexmargins

Why do Top-Aligned Minipages Create a Vertical Margin?


Using the following bit of code, I experience unwanted behaviour.

\documentclass[11pt,a4paper]{letter}

\usepackage[sfdefault]{roboto}
\usepackage[german]{babel}
\usepackage[a4paper, showframe, margin=24mm]{geometry}
\usepackage{graphicx}

\begin{document}

\begin{minipage}[t]{14mm}
\vspace{0pt}
\includegraphics[height=17mm]{Placeholder.pdf}
\end{minipage}
\hfill
\begin{minipage}[t]{100mm}
\flushright
\vspace{0pt}
Lorem Ipsum\\
dolor sit amet\\
consetetur sadipscing elitr
\end{minipage}
\vspace*{50mm}

\today

\end{document}

The result: https://i.sstatic.net/PMzu9.png

Where does the vertical space between frame and content of the minipages come from and how can I eliminate it?

I tried these things:

  • No \vspace{0pt}. The logo placeholder moves to the frame (where I want it), but the text moves down more.
  • \vspace{0pt} only in first minipage. Text moves up to the frame (where I want it), but logo placeholder has the unwanted margin.
  • Minipages with given height of 25 mm via \begin{minipage}[t][25mm]{100mm}. No effect.

I've had these issues with minipages for a long time. Maybe I misunderstood something? I'm also grateful for hints on how to achieve what I want with other methods than minipages.

Thanks for your help.


Solution

  • I'd go for your first solution with no \vspace{0pt}. To get the correct image alignment, you can use the valign option from the adjustbox package:

    \documentclass[11pt,a4paper]{letter}
    
    \usepackage[sfdefault]{roboto}
    \usepackage[german]{babel}
    \usepackage[a4paper, showframe, margin=24mm]{geometry}
    \usepackage{graphicx}
    
    \usepackage[export]{adjustbox}
    
    \begin{document}
    
    \begin{minipage}[t]{3cm}%
    \includegraphics[height=17mm,valign=t]{example-image-duck}
    \end{minipage}%
    \hfill
    \begin{minipage}[t]{100mm}
    \flushright
    Lorem Ipsum\\
    dolor sit amet\\
    consetetur sadipscing elitr
    \end{minipage}%
    
    \vspace*{50mm}
    
    \today
    
    \end{document}
    

    enter image description here