12

The package microtype is meant to make small improvements to the final look of a LaTeX document. According to an answer to Should I load microtype with pdflatex? and a comment beneath the answer, one should (almost) always load microtype, and do so via

\makeatletter\usepackage{microtype}\g@addto@macro\@verbatim{\microtypesetup{activate=false}}\makeatother%

also: enumitem


Without microtype, here is the output. Notice how "(2D)" and "(3D)" are nicely aligned:

Alignment of (2D) and (3D) without microtype

With microtype, output is altered. Notice that "(2D)" and "(3D)" are not aligned. The "(3D)" part is too far left:

Alignment of (2D) and (3D) with microtype


Granted, this is not a big effect but still annoying. I do not think this is an intended effect of microtype but I am not sure... More importantly:

  • Q: Can I fix it AND still keep microtype?

    (Fix it = "(2D)" and "(3D)" are aligned again; of course, should be done automatically and globally for other similar situations as well)


MWE (to enable microtype, uncomment the corresponding line in code):

\documentclass{book}

\usepackage{enumitem}

%\makeatletter\usepackage{microtype}\g@addto@macro\@verbatim{\microtypesetup{activate=false}}\makeatother% %uncomment to see the left-shift


\begin{document}

    \begin{enumerate}
        \item (2D) Some test here.
        
        (3D) This is too far to the left wrt to (2D) (!very slightly!) with microtype.
        
        \item Some other text here.
    \end{enumerate}
    

\end{document}

I am running pdflatex 3.141592653-2.6-1.40.22 (MikTeX 21.3), and every package in my local distrubution was updated on 28/04/2021. Output is identical (in terms of misalignment) on Overleaf with default settings.

2
  • 1
    See this answer (different environment but same problem) – Robert May 7 at 14:35
  • @Robert Thank you for the useful reference. It does indeed seem to be a related problem. – Linear Christmas May 7 at 19:23
6

Whereas one approach would be to inhibit protrusion everywhere, this approach is to force protrusion on left parentheses that follow an invocation of \item, which I do by redefining \item to look at what follows.

\documentclass{book}

\usepackage{enumitem}
%
\usepackage{microtype}
\makeatletter
\g@addto@macro\@verbatim{\microtypesetup{activate=false}}% %uncomment to see the left-shift

\let\svitem\item
\renewcommand\item[1][\relax]{%
  \ifx\relax#1
    \svitem
  \else
    \svitem[#1]
  \fi
  \@ifnextchar({\hspace{-1.2pt}}{}%
}
\makeatother
\begin{document}
    \begin{enumerate}
        \item (2D) Some test here.
        
        (3D) This is too far to the left wrt to (2D) (!very slightly!) with microtype.
        
        \item Some other text here.
    \end{enumerate}
\end{document}

enter image description here

This could be equivalently done also with xpatch's macro \apptocmd:

\documentclass{book}

\usepackage{enumitem,xpatch}
%
\usepackage{microtype}
\makeatletter
\g@addto@macro\@verbatim{\microtypesetup{activate=false}}% %uncomment to see the left-shift

\apptocmd{\item}{\@ifnextchar({\hspace{-1.2pt}}{}}{}{}
\makeatother
\begin{document}
    \begin{enumerate}
        \item (2D) Some test here.
        
        (3D) This is too far to the left wrt to (2D) (!very slightly!) with microtype.
        
        \item Some other text here.
    \end{enumerate}
\end{document}
6
  • Thank you for the answer. I like it! Is it correct to say that \@ifnextchar will look at only the next character, and do the left-alignment fix if the character is (? So if one had \item \relax [2D) and \item (3D) instead, then one should also do \apptocmd{\item}{\@ifnextchar\relax{\hspace{-1.2pt}}{}}{}{}? – Linear Christmas May 7 at 19:30
  • @LinearChristmas I would say, no. If you change both the secondary line from (3D) to [3D], and the first line to \item\relax[2D], you will see that [ needs no adjustment when immediately following \item – Steven B. Segletes May 8 at 7:46
  • Thank you for commenting. I meant that only the first line is changed, i.e. \item \relax [2D) instead of \item (2D) but \item (3D) stays the same. – Linear Christmas May 8 at 11:05
  • @LinearChristmas At that point, you are effectively disagreeing with microtype's decision to allow protrusion for (, but not [. Rather than entertain such a notion, it would be preferable, in my estimation, to turn off protrusion altogether. – Steven B. Segletes May 8 at 11:10
  • Okay, noted, thank you. One last thing: how did you come up with -1.2pt in \hspace{-1.2pt}. I assume you did not simply eyeball it? – Linear Christmas May 8 at 14:44
12

Note that this only happen when the line start with "(" but not with characters like a "E". This is a side effect of protrusion (= margin kerning), that move "(" a bit to the left, to have a more harmonious margin, but in this case seems the opposite because the protrusion is not applicable after the item number.

An occasional dirty solution for this case could be some as \makebox[0pt]{} before the parenthesis, since a box of 0pt will be not protruded to the left (note that \makebox{} without specified width will not correct the protrusion), or disable the protrusion locally with \microtypesetup{protrusion=false}.

A general fix could be disabling the protrusion before for any enumerated list:

\documentclass{book}
\usepackage{microtype}
\AtBeginEnvironment{enumerate}{\microtypesetup{protrusion=false}}
\begin{document}
\begin{enumerate} \item E\par E\end{enumerate}
\begin{enumerate} \item (E\par (E \end{enumerate}
\end{document}
 
5
  • Thank you very much for the answer! Two things: 1) You say that ' [Protrusion] only [happens] when the line start with "(" '. Is that really the sole character where this happens? 2) Do I understand correctly that with this solution: if one has two consecutive enumerate environments (as in your MWE), then the contents of the second one will seem "a bit to the right" if starts with "("? (assuming, of course, that protrusion is disabled globally in all enumerate environments) Perhaps adding a picture of this to the answer is a good idea :) – Linear Christmas May 7 at 19:18
  • @LinearChristmas 1) I meant that it does not happen with most characters. It happens also with some other signs: endash, emdash, quotation, asterisk, ... that could produce an effect of ragged margin 2) Consider \noindent E\\(E\\E\\(E\\E\\(E\\E: the even lines seems intended without protrusion, but they are perfectly aligned. The protrusion really misalign that lines, but the margin look better. However, when there are few lines to produce that effect, as in the MWE, that dirty trick gets too obvious. – Fran May 7 at 21:41
  • Thanks for the extra information. For the benefit of future readers: Fran's solution and Steven's solution (with \begin{document} \begin{enumerate} \item E\par E\end{enumerate} \begin{enumerate} \item (E\par (E \end{enumerate} \end{document}). – Linear Christmas May 8 at 13:54
  • 1
    @LinearChristmas The apparent extra space that you note before the "(" without protrusion is not a misalignment. That left space is the inherent to the character by typographic design. You will see what I mean if you make a \fboxsep0pt\fboxrule.05pt\fbox{(}: the same extra space is inside the box. Or just compare space in ")(" versus "OO", for instance. If you are very picky about margins, note that you can make a micro fine tuning of particular character (page 12 of the manual). – Fran May 8 at 20:25
  • Thank you for pointing this out! That's new and useful information to me. – Linear Christmas May 9 at 16:46
0

If one does not mind the extra vertical space, one could also use the following solution which adds \item[] in front of (3D).

\documentclass{book}

\usepackage{enumitem}

\makeatletter\usepackage{microtype}\g@addto@macro\@verbatim{\microtypesetup{activate=false}}\makeatother% %uncomment to see the left-shift


\begin{document}

    \begin{enumerate}
        \item (2D) Some test here.
        
        \item[] (3D) This is too far to the left wrt to (2D) (!very slightly!) with microtype.
        
        \item Some other text here.
    \end{enumerate}

\end{document}

The output is

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.