Text FormattingHow to make equations within enumerate centered on page

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
kingliam
Posts: 5
Joined: Wed Jan 22, 2025 7:22 pm

How to make equations within enumerate centered on page

Post by kingliam »

I am trying to display an equation within an enumerated list. I want the equation to be centered to the page, but it is instead centered to the space available within the enumerated element. An example is shown below:

https://www.overleaf.com/read/mmgsmbfymmqk#1ee955

How do I make the equation center to the page.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics
User avatar
Stefan Kottwitz
Site Admin
Posts: 10281
Joined: Mon Mar 10, 2008 9:44 pm

Re: How to make equations within enumerate centered on page

Post by Stefan Kottwitz »

Hello,

there was no quick answer, perhaps because the code was not included here. Very good that you made an example, but please post it as code here in the forum, instead of an Internet link to some external service.

If you embed an equation within an enumerate list, it gets centered in this list. To center it outside of the list, on the page, it shouldn't be within the list. Luckily you can suspend and resume a list for such a purpose, with the enumitem package, like this:

Code: Select all

\documentclass{article}
\usepackage{enumitem}
\begin{document}
\begin{equation}
  x = 1
\end{equation}\begin{enumerate}
  \item Text
  \item More text
\end{enumerate}
\begin{equation}
  y = 1
\end{equation}
\begin{enumerate}[resume]
  \item Text
\end{enumerate}
\end{document}
Stefan
LaTeX.org admin
kingliam
Posts: 5
Joined: Wed Jan 22, 2025 7:22 pm

Re: How to make equations within enumerate centered on page

Post by kingliam »

Thank you. I will post code here from now on.

I have a follow up question. The method works great until I start nesting enumerated lists. If I try to resume twice, it does not work. I have written the following code, which does work, but is very clunky. I tried to make an environment, but was unsuccessful because I want to have \end statements before \begin statements, as I want to \end an environment outside of this custom environment. Any suggestions on how to do this, or if a different solution is better for what I want?

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\usepackage{enumitem}

\begin{document}
\begin{equation*}
x = 1
\end{equation*}

\newcounter{outer}
\newcounter{inner}

\begin{enumerate}
\item Outer 1
\setcounter{outer}{\value{enumi}}

\begin{enumerate}
\item item a
\item item b

% Ideally would have environment or another tool to not have all of this code every time I want a centered equation
\setcounter{inner}{\value{enumii}}
\end{enumerate}
\end{enumerate}
\vspace{-1em}
\begin{align*}
x=1
\end{align*}
\begin{enumerate}
\item[]
\setcounter{enumi}{\value{outer}}
\begin{enumerate}
\setcounter{enumii}{\value{inner}}
% End equation code

\item item c
\end{enumerate}
\item Outer 2
\end{enumerate}

\end{document}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10281
Joined: Mon Mar 10, 2008 9:44 pm

Re: How to make equations within enumerate centered on page

Post by Stefan Kottwitz »

Within such a list environment, things are within its text area and not in the outer page area. In a logical structure, the list environment should end before another displayed item comes centered between the page margins. Resuming one list is easy, resuming from nested lists can get messy, which may be the price to pay for an unusual not really consequent logical structure. Especially when you structure using nested list, then really consider having equations aligned to the list level, or do something less complicated.

Stefan
LaTeX.org admin
Post Reply