4

Let's say I want to write a list of exercises using enumerate. For each item of the list, the correct answer is given at the end of the line, and it is written between square brackets. This is how I would write it:

\documentclass{article}

\usepackage{amsmath}

\begin{document}
\begin{enumerate}
    \item $2a=4$ \hfill $\left[a=2\right]$
    \item $2a=1$ \hfill $\left[a=\frac{1}{2}\right]$
    \item $3a=6$ \hfill $\left[a=2\right]$
\end{enumerate}
\end{document}

However, the square brackets at the end of the lines are not correctly aligned to each other:

Bigger brackets get an unwanted space

I can't figure out the reason of this behaviour: adding \mathclose{} after \right does not help. It is not an enumerate issue, since the problem still appears if I remove the enumerate setting and go to a new line manually.

5

What's happening is that because you're using \left and \right, you're getting a slightly larger (and different) closing square bracket on the line with the fraction. Each slightly larger bracket, by the way, adds a little bit more space around it. Because this is actually built into the character design, eliminating it would be challenging at best. A lot depends on what your solutions on the right look like. You can get away without \left...\right on your brackets if you aren't having especially tall answers (e.g., simple fractions should be fine, but \frac{a^2}{b} might look weird). Perhaps using color instead of brackets to mark your answers would be better? Or alternatively putting them in boxes instead of brackets. In any event, you would want to wrap everything up in a macro definition, e.g.,

\newcommand*[1]\answer{\hfill\fbox{#1}
...
\item $2a=4$ \answer{$a=2$}

This has the advantage that you could use the same source for the solution-free question list by defining

\newcommand*[1]\answer{}
| improve this answer | |
  • Thank you very much: I'm trying with boxes and it seems quite a nice solution. Yes, the purpose was to define a new macro, but I was trying to be as clean as I could here (and still, I received a comment saying the question was not understandable). – Mattia Vedovato Aug 25 at 16:38
  • 1
    @MattiaVedovato I saw that comment. I didn't understand it. 🤷🏻‍♂️ – Don Hosek Aug 25 at 16:44

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.