Text FormattingConflict between linenumbers and align

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
FrankCamilleBoscan
Posts: 1
Joined: Sat Feb 25, 2023 5:07 pm

Conflict between linenumbers and align

Post by FrankCamilleBoscan »

It would appear that trying to use "linenumbers" within an "align" structure is not possible, and vice versa. Does anyone have a workaround ?

For example, I would like to be able to combine this structure

Code: Select all

\begin{linenumbers}
        \indent $limit = n*n$ \\
        \indent $sum = 0$ \\
        \indent $\mathbf{for}$ $i = 1$ $\mathbf{to}$ $limit$ \\
        \indent\indent $sum = sum + 1$ \\
        \indent $\mathbf{return}$ $sum$
\end{linenumbers}
with this one

Code: Select all

\begin{align*}
        T(n) &= c_1 + c_2 + c_3n^2 + c_4n^2 + c5 \tag{comment 1} \\
        &= c + c'n^2 \in \Theta(n^2) \tag{comment 2}
\end{align*}
This would allow me to comment lines of code.

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

kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

Conflict between linenumbers and align

Post by kaiserkarl13 »

I am assuming you are using the lineno package. If so, then this will work if you surround your displayed environments with \begin{linenomath}...\end{linenomath}. If you want the display lines themselves to be numbered, use the starred version of the same environment. This is explained in the documentation.
Post Reply