2

I am trying to combine enumeration over multiple sections: it is not working.

\documentclass[12pt]{article}
\usepackage[top = 1in, bottom = 1in, left = 1in, right = 1in]{geometry}
\usepackage[usenames,dvipsnames]{xcolor}

\begin{document}

\begin{enumerate} 

\begin{center} 
\textbf{class X}
\end{center}

\item \hangindent=7mm \noindent \footnotesize \textcolor{blue}{AAAAA} \normalsize
\item \hangindent=7mm \noindent BBBBB

\begin{center} 
\textbf{class Y}
\end{center}

\item \hangindent=7mm \noindent \footnotesize \textcolor{blue}{CCCCC} \normalsize

\end{enumerate} 

\end{document}

I get the error

Something's wrong--perhaps a missing \item.

How do I achieve enumeration automatically for all items marked \item while not enumerating section titles placed in between them?

EDIT: the answer below results in the centered section heading actually being offcenter, to the right a bit. How do I completely center them?

3

You can use enumitem and its resume macro.

\documentclass[12pt]{article}
\usepackage[top = 1in, bottom = 1in, left = 1in, right = 1in]{geometry}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{showframe}   %% to show the page grid. Remove!
\usepackage{enumitem}

\begin{document}
\noindent X\dotfill X
\begin{center}
\textbf{class X}
\end{center}

\begin{enumerate}
\item \footnotesize \textcolor{blue}{AAAAA} \normalsize
\item  BBBBB
\end{enumerate}

\begin{center}
\textbf{class Y}
\end{center}

\begin{enumerate}[resume]
\item \footnotesize \textcolor{blue}{CCCCC} \normalsize
\end{enumerate}

\end{document}

enter image description here

  • Apparently we posted the very same approach at the same time. :) I'll delete mine in favour of yours. :) – Paulo Cereda Nov 4 '13 at 13:43
  • @PauloCereda: Oho! I didn't see your answer Paulo (slow internet). But you are early by 2 minutes. – user11232 Nov 4 '13 at 13:47
  • Nah don't worry. :) – Paulo Cereda Nov 4 '13 at 13:49
1

Is this what you seek? What I did was use \hfils and \hfills, instead of centering, and made the headers \items without a label.

\documentclass[12pt]{article}
\usepackage[top = 1in, bottom = 1in, left = 1in, right = 1in]{geometry}
\usepackage[usenames,dvipsnames]{xcolor}

\begin{document}

\begin{enumerate} 

\item[] \hfil\textbf{class X}\hspace{\the\leftmargin}\hfill


\item \hangindent=7mm \noindent \footnotesize \textcolor{blue}{AAAAA} \normalsize
\item \hangindent=7mm \noindent BBBBB

\item[] \hfil\textbf{class Y}\hspace{\the\leftmargin}\hfill

\item \hangindent=7mm \noindent \footnotesize \textcolor{blue}{CCCCC} \normalsize

\end{enumerate} 

\centering CENTERED

\end{document}

enter image description here

EDITED to achieve centering of enumerated headers. An \hspace is added after the header and before the \hfill. The amount (set to \the\leftmargin) corresponds to the indentation level of the environment.

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.