TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In this code as here:

\begin{enumerate}[label=\bfseries Exercise \arabic*:]
   \item 5 + 7 = 12
   \item 9 + 1 = 10
   \item 2 * 2 = 4
\end{enumerate}

I want the text Exercise (with its number) to be center-align and the content after that to be below and left-align. Anybody can help. Thanks.

share|improve this question
1  
You mean so that \item 5 + 7 = 12 translates into "Exercise 1 <newline> 5 + 7 = 12". Or is each enumerate block prefaced by the Exercise ? – jon Feb 12 at 4:08
    
@jon I mean: Exercise 1 <newline> 5 + 7 = 12 – Exdata Feb 12 at 4:21
up vote 4 down vote accepted

Here is one way to achieve the desired results:

enter image description here

Improvements

  • Note that there is a -5.0pt tweak to the labelwidth to compensate for the with of the label. This really should be computed based on other enumitem lengths.

Code:

\documentclass{amsart}

\usepackage{enumitem}
\usepackage{showframe}

\SetLabelAlign{center}{\hss#1\hss}

\begin{document}
\begin{enumerate}[label={\bfseries Exercise \arabic*},
    align=center,
    labelwidth=\dimexpr\linewidth-5.0pt\relax,
    leftmargin=!,
    style=unboxed,
    ]
   \item 5 + 7 = 12
   \item 9 + 1 = 10
   \item 2 * 2 = 4
\end{enumerate}
\end{document}
share|improve this answer
    
Thank Peter Grill and Andrew very much. This helps resolve my problem. But I don't understand why you can add those things. What lines in what pages in what documents you use for the added code above. I have read over and over enumitem documentation but I can't resolve the problem. You two great! – Exdata Feb 12 at 8:03
    
@Exdata: This really is not what lists are intended for thus I think it'll be difficult to find such an example in the documentation. But you could search the enumitem documentation for \SetLabelAlign where there is a related example without the second hss and meaning of labelwidth. – Peter Grill Feb 12 at 8:06

Why in an enumerate environment? I might be inclined to cheat if that is the input (though I hope it is not if you are actually typesetting math).

\documentclass{article}
\usepackage{lipsum,showframe}

\newcounter{exercise}
\setcounter{exercise}{0}
\renewcommand{\theexercise}{\arabic{exercise}}
\newcommand\iitem[1]{%
%\begingroup
  \refstepcounter{exercise}%
  \parindent0pt
  {\centering
    \textbf{Exercise \theexercise}\par} #1%
%\endgroup
}

\begin{document}

\section{S One}

\lipsum[1]%\label{zzz}

\iitem 5 + 7 = 12

\iitem 9 + 1 = 10

\iitem 2 * 2 = 4\label{asdf}

See Exercise \ref{asdf}.
\lipsum[1]

\end{document}

Of course, as soon as you want to include real math, you're going to need far more robust commands....

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.