2

I would like to align the tops of two minipages.

Here is a MWE:

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{lipsum}
\begin{document}
  \noindent
  \hfill
  \begin{minipage}{0.49\textwidth}
    What do you think of this situation?

    \vspace{1cm}
    \begin{center}
    \underline{\hspace{0.75\textwidth}}
    \end{center}
  \end{minipage}
  \hfill
  \begin{minipage}{0.49\textwidth}
    \begin{tcolorbox}
      \lipsum[1]
    \end{tcolorbox}
  \end{minipage}
  \hfill
\end{document}

Here is the output I get using pdflatex:

enter image description here

I would like the "What do you think of this situation?" text to be at the top. Is there a way to do it? I would like to avoid explicitly setting the height of the minipages since the lipsum text could change later.

3
  • 2
    Use \begin{minipage}[t]{<width>} on both your minipages.
    – Skillmon
    Commented Mar 7 at 13:38
  • That doesn't do it in this case. It seems tcolorbox causes an issue unless we add box align=top.
    – Duncan
    Commented Mar 7 at 14:15
  • 1
    Another trick is to add \hrule height0pt as the first line in each minipage. Technically, [t] aligns the baseline of the first line, which in this case would be the very top. Commented Mar 7 at 15:14

2 Answers 2

4

Normally, you could use \begin{minipage}[t]{<width>} to top align the minipages, like @Skillmon suggested in the comments.

For the specific case of a tcolorbox, you should combine this with the box align=top option as tcolorboxes are normally bottom aligned. If you like you can fine tune the alignment to line up the first lines of text:

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{lipsum}
\usepackage{adjustbox}

\begin{document}
  \noindent
  \begin{minipage}[t]{0.49\textwidth}
    \vskip2.2ex
    
    What do you think of this situation?

    \vspace{1cm}
    \begin{center}
    \underline{\hspace{0.75\textwidth}}
    \end{center}
  \end{minipage}%
  \begin{minipage}[t]{0.49\textwidth}
    \begin{tcolorbox}[box align=top]
      \lipsum[1]
    \end{tcolorbox}
  \end{minipage}%

\end{document}

enter image description here

Or you could ditch the minipages:

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}

\begin{document}
  \noindent
  \begin{tcolorbox}[width=0.49\textwidth,nobeforeafter,box align=top,enhanced,frame hidden,interior hidden,left=0pt,right=0pt]
    What do you think of this situation?

    \vspace{1cm}
    \begin{center}
    \underline{\hspace{0.75\textwidth}}
    \end{center}
  \end{tcolorbox}%
  \begin{tcolorbox}[width=0.49\textwidth,nobeforeafter,box align=top]
    \lipsum[1]
  \end{tcolorbox}%


\end{document}

enter image description here

4
  • Thank you, box align=top helped a lot. I wish there were a solution that did not require fine-tuning the vspace though.
    – Duncan
    Commented Mar 7 at 14:07
  • @Duncan If you don't want to fine-tune the spacing, you could ditch the minipages and use tcolorboxes for both columns Commented Mar 7 at 14:14
  • Great idea! Thanks for adding that to your post.
    – Duncan
    Commented Mar 7 at 14:18
  • @Duncan You're welcome! Commented Mar 7 at 14:18
2

Another possibility is to use the \adjustbox package. I also set the margins with \showframe.

Note: the last \hfill does nothing, I changed the widths of the minipages to see better. See this post Understanding the Need for \null After \hfill in LaTeX Figure Environment

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{adjustbox}
\usepackage{showframe}%<-- comment in the final document
\usepackage{lipsum}
\begin{document}
  \noindent
  \hfil%
  \adjustbox{valign=t}{\begin{minipage}{0.3\textwidth}
    What do you think of this situation?
    \vspace{1cm}
    \begin{center}
    \underline{\hspace{0.75\textwidth}}
    \end{center}
  \end{minipage}%
  }
  \hfil%
  \adjustbox{valign=t}{\begin{minipage}{0.5\textwidth}
    \begin{tcolorbox}
      \lipsum[1]
    \end{tcolorbox}
  \end{minipage}%
  }
\end{document}

enter image description here

You must log in to answer this question.

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