1

I'm writing out some lines in the align* environment and I want to add a comment to one line, and then it shifts the entire section over to the left. Ideally I'd want align to center the equations and ignore the text in the alignment.

For now I'm not overly concerned with what happens if I end up needing to wrap the text over multiple lines, but I'd be interested in how to deal with that as well.

Sample code:

\begin{align*}
    a &= b+c\\
    b &= a-c
\end{align*}

\begin{align*}
    a &= b+c \text{this comment should not affect the position.}\\
    b &= a-c
\end{align*}
3
  • Welcome to TeX StackExchange! Are you perhaps looking for something like \tag{some text}?
    – gz839918
    Sep 27, 2023 at 23:46
  • @gz839918 That looks good, but the spacing seems to affect the alignment anyway. Is there a way to reduce this spacing? Sep 28, 2023 at 0:16
  • The spacing exists to prevent text from overflowing onto the equation and affecting the appearance of the document. There's probably some way to disable it, but I don't know personally.
    – gz839918
    Sep 28, 2023 at 0:24

1 Answer 1

1

This effectively requests the comment to be set in a zero-width box. This will, however, cause (lengthy) content to spill over into the margin.

enter image description here

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align*}
  a &= b + c \\
  b &= a - c
\end{align*}

\begin{align*}
  a &= b + c \makebox[0pt][l]{~this comment should not affect the position.} \\
  b &= a - c
\end{align*}

\end{document}

In those instances, you can use a tabular to structure the content vertically:

enter image description here

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{align*}
  a &= b + c \\
  b &= a - c
\end{align*}

\begin{align*}
  a &= b + c \makebox[0pt][l]{~%
    \begin{tabular}[t]{@{}l@{}}
      this comment should not \\ 
      affect the position.\end{tabular}} \\
  b &= a - c
\end{align*}

\end{document}
1
  • That seems to give everything I was hoping for! Thank you! Sep 28, 2023 at 2:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .