Why adjustbox needs a tweak of raise=-0.3ex with enumitem?

The option valign=t of adjustbox doesn't retrieve the inner top baseline as the [t] option of minipage or tabular do. adjustbox calculates a height which takes the current text font size into account: by default valign=t sets the height to the height of the current \strutbox.

This means that depending on the text on the first line it can be too high or too low relative to the number. You can "repair" the first case with the code from Mico but for the second case there is no easy fix.

In my opinion adjustbox is the wrong environment for such boxes. It is useful for aligning pictures which have no intrinsic baseline, but not for text boxes.

\documentclass{article}
\usepackage{enumitem}
\usepackage[export]{adjustbox}

\newadjustboxenv{MyAdjustbox}{valign=t}

\begin{document}
    \begin{enumerate}
    \item
        \begin{MyAdjustbox}%too high
             \begin{minipage}[t]{\linewidth}
                aaaa
             \end{minipage}%
       \end{MyAdjustbox}
    \item  \begin{MyAdjustbox}%too low
             \begin{minipage}[t]{\linewidth}
              $\int\limits_1^3 f(x) $
             \end{minipage}%
       \end{MyAdjustbox} 
   \end{enumerate}
\end{document}

enter image description here


I think that there are two separate issues. The main one arises from the use of a minipage environment.

  • The first row in the material inside the fbox has no material taller than uppercase letters. Because that material is encased in a minipage, the unused vertical whitespace needed for symbols such as ( and ) is removed. In contrast, the enumeration symbol is not encased in a minipage, and hence its baseline is chosen without removing the implicit \strut. If one inserts a \strut in the first line of the \fbox, most of the need for vertical adjustment is removed.

  • To fully align the baselines of the "1." particle before the \fbox and the material inside the minipage, one also needs to make an adjustment (pun intended) for the thickness of the rule (given by the parameter \fboxrule; default value: \arrayrulewidth, usually 0.4pt) that surrounds the fbox. And, since the value of \fboxsep is nonzero in general, I suggest using the following code

    \newadjustboxenv{MyAdjustbox}{valign=t, raise=\fboxrule+\fboxsep}
    

    in lieu of

    \newadjustboxenv{MyAdjustbox}{valign=t, raise=-0.3ex}
    

With these two adjustments (yet another pun -- ouch!), I get this screenshot:

enter image description here

\documentclass{article}
\usepackage{enumitem}
\usepackage[export]{adjustbox}

\fboxsep=0pt

\newadjustboxenv{MyAdjustbox}{valign=t, raise=\fboxrule+\fboxsep}

\begin{document}
    \begin{enumerate}
    \item 
    \begin{MyAdjustbox}
       \fbox{%
       \begin{minipage}{\linewidth}\strut%
       Some text that takes up several lines, so we need 
       to adjust the item number to align with the top 
       baseline.
      \end{minipage}%
      }%
   \end{MyAdjustbox}%
   \end{enumerate}%
\end{document}