8

I want to align the top of an image, and the top of a line of text. Below is a MWE with the current setup (using a placeholder "graphic" but the effect seems the same) and the desired behavior.

\documentclass{article}

\usepackage{graphicx}

\begin{document}

    \begin{minipage}[t]{0.5\textwidth}
        %\includegraphics[height=0.4in]{theimage.png}
        \rule{0.95\textwidth}{0.5in}
    \end{minipage}%
    \begin{minipage}[t]{0.5\textwidth}
        sometext to fill the line
    \end{minipage}

\end{document}

MWE behavior:

MWE behavior

Desired behavior:

enter image description here

3
  • Welcome to TeX.SE! Please have a look at this post.
    – user121799
    Commented Aug 22, 2018 at 4:00
  • Isn't this what you want? tex.stackexchange.com/questions/29143/… Commented Aug 22, 2018 at 12:45
  • thanks to both of you, I was having trouble locating these resources by searches. Should have searched harder I guess.
    – amoodie
    Commented Aug 22, 2018 at 13:56

3 Answers 3

5

A simple way to fix your problem is by adding \vspace{0pt} as soon as a minipage is created:

Output

\documentclass{article}

\usepackage{graphicx}

\begin{document}
  \begin{minipage}[t]{0.5\textwidth}
    \vspace{0pt}
    %\includegraphics[height=0.4in]{theimage.png}
    \rule{0.95\textwidth}{0.5in}
  \end{minipage}%
  \begin{minipage}[t]{0.5\textwidth}
    \vspace{0pt}
    sometext to fill the line
  \end{minipage}
\end{document}
1
  • 4
    This also feels a little hacky (similar to my answer below) but it works. Can you explain why adding the zero-height vspace works in this case?
    – amoodie
    Commented Aug 22, 2018 at 13:57
8

You could use adjustbox, as marmot suggested in his comment.

Moreover, instead of using minipages, you could use a tabularx.

\documentclass{article}
\usepackage{tabularx}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\begin{document}
\noindent\begin{tabularx}{\linewidth}{@{}X@{\hspace{2pt}}X@{}}
        \includegraphics[height=0.4in, width=0.475\textwidth,valign=t]{example-image}
    &
        sometext to fill the line \\
\end{tabularx}
\end{document}

enter image description here

0

A potential workaround I found is that if I know the height of the image, I can add a negative vspace. This seems kind of hacky though and I'm wondering if there is a cleaner solution

\documentclass{article}

\usepackage{graphicx}

\begin{document}

    \begin{minipage}[t]{0.5\textwidth}
        % \includegraphics[height=0.4in]{theimage.png}%
        \rule{0.95\textwidth}{4\baselineskip}
    \end{minipage}%
    \begin{minipage}[t]{0.5\textwidth}
        \vspace*{-4\baselineskip}
        sometext to fill the line
    \end{minipage}

\end{document}

You must log in to answer this question.

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