Math & ScienceControl Spacing of Comments in aligned Equations

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

Control Spacing of Comments in aligned Equations

Post by jaybz »

How can I decrease the amount of space between the comments and the math in the following ?

Code: Select all

\documentclass[11pt]{article}
\usepackage{mathtools}
\begin{document}
\begin{align*}
    3+x &=4 && \text{comment}\\
    x &=4-3 && \text{another comment}\\
    x &=1  && \text{yet another comment}\\ 
\end{align*}
\end{document}
Last edited by jaybz on Thu May 10, 2012 5:38 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

kajal
Posts: 6
Joined: Thu Apr 26, 2012 5:25 pm

Control Spacing of Comments in aligned Equations

Post by kajal »

Hi,
Just use \hspace and set the values (I use -2.7cm)

Code: Select all

\documentclass[11pt]{article}
\usepackage{mathtools}
\begin{document}
\begin{align*}
    3+x &=4 && \hspace{-2.7cm}\text{comment}\\
    x &=4-3 && \hspace{-2.7cm}\text{another comment}\\
    x &=1  && \hspace{-2.7cm}\text{yet another comment}\\
\end{align*}
\end{document}
Last edited by localghost on Thu May 10, 2012 10:10 am, edited 2 times in total.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Control Spacing of Comments in aligned Equations

Post by localghost »

You can alternatively use the alignat* environment to have more control about the horizontal space.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}  % loads »amsmath«

\begin{document}
 \begin{alignat*}{2}
    3+x &=4   & \quad & \text{comment}             \\
      x &=4-3 &       & \text{another comment}     \\
      x &=1   &       & \text{yet another comment}
  \end{alignat*}
\end{document}
Details can be found in the amsmath manual.


Thorsten
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

Re: Control Spacing of Comments in aligned Equations

Post by jaybz »

I try to use negative hspace and vspace only as a last resort but thank you for the response kajal. The alignat method works fine, I'll use that. Thank you localghost.
Post Reply