1

I'm using booktabs cmidrule in a math align environment. It's working but it's producing too much vertical space. How can I reduce that vertical space.

Here's a simple demo

cmidrule has excess vertical spacing

\documentclass{article}

\usepackage{amsmath}
\usepackage{booktabs}

\begin{document}

\begin{align*}
  % dummy placeholder equations. highlight spacing
  1 + 1 &= 2 \\
  1 + 1 &= 2 \\
  \cmidrule{1-2}
  2 + 2 &= 4 \\
  2 + 2 &= 4 \\
\end{align*}

\end{document}
3
  • Do you need to use align here? – Werner Feb 26 at 3:08
  • I do want to align a list of equations. Someone else suggests array however \tag{eq1} doesn't seem to work with that. What else do you recommend? – clay Feb 26 at 5:20
  • 1
    I'd suggest the other other answer then as it allows you still use \tags. You can also capture the horizontal coordinate of the widest elements within your align and then draw a rule to match the horizontal width of the construction. – Werner Feb 26 at 19:39
2

In a way, I'm surprised that \cmidrule works at all outside of tabular-like and array environments. The fact the use of \cmidrule doesn't throw an immediate error message is not an indication that what you're doing can or should be expected to produce the result you're hoping to get.

If you must use \cmidrule, do typeset the equations in question in an array environment.

enter image description here

\documentclass{article}
\usepackage{array,amsmath,booktabs}
\newcolumntype{L}{>{\displaystyle}l}
\newcolumntype{R}{>{\displaystyle}r}

\begin{document}

\begin{minipage}[t]{0.22\textwidth}
\texttt{array} approach
\[
\renewcommand{\arraystretch}{1.28} % emulate display-style math setting
\begin{array}{@{} R @{{}={}} L @{}}
  1 + 1 & 2 \\
  1 + 1 & 2 \\
  \cmidrule{1-2}
  2 + 2 & 4 \\
  2 + 2 & 4 
\end{array}
\]
\end{minipage}\quad
\begin{minipage}[t]{0.22\textwidth}
\texttt{align*} approach
\begin{align*}
  1 + 1 &= 2 \\
  1 + 1 &= 2 \\
  \cmidrule{1-2}
  2 + 2 &= 4 \\
  2 + 2 &= 4 \\
\end{align*}
\end{minipage}
\end{document}
4
  • This is excellent. Except \tag{eq1} doesn't work with array like it does with align. Is that another thread entirely? The spacing with array is perfect. – clay Feb 26 at 5:20
  • Also, if I may ask, how would a user know that cmidrule isn't supposed to work inside align* but is supposed to work inside of array? – clay Feb 26 at 5:44
  • 1
    @clay - The title of the user guide of the booktabs package is "Publication quality tables in LATEX", and the document goes on to mention tabular-like and array environments (which share a lot of code "under the hood") at great length; not a single example with a multi-line display math environment in the entire document, though. Please note that I did not claim that "\cmidrule isn't supposed to work inside align*"; instead, I expressed my surprise that it works at all (though rather imperfectly). You can still use \tag to associate a single equation number with the array. – Mico Feb 26 at 5:51
  • 1
    @clay - If you need to find out how number individual rows of an array environment, please post a new query. – Mico Feb 26 at 5:55
1

If you want to reduce vertical space in this example or in a similar case add negative space before, for example with \\[-2ex]

In addition to the excessive space you notice booktabs adds vertical space both sides of the \cmidrule so it is harder to correct.

\documentclass{article}

\usepackage{amsmath}
%\usepackage{booktabs}

\begin{document}

\begin{align*}
  % dummy placeholder equations. highlight spacing
  1 + 1 &= 2 \\
  1 + 1 &= 2 \\[-1.5ex]
  \cline{1-2}
  2 + 2 &= 4 \\
  2 + 2 &= 4 \\
\end{align*}

\end{document}

x

2
  • Your write-up appears to suggest that the chief reason for the excessive amount of vertical whitespace padding shown in the OP's screenshot is the fact that \cmidrule{1-2} adds vertical space. That's not quite right, though, as your own code -- which uses \cline{1-2} instead of \cmidrule{1-2} -- demonstrates. – Mico Feb 26 at 4:52
  • Right. I corrected my comment. Thank you for your feedback. – Simon Dispa Feb 26 at 5:30

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.