2

I have used

\section*{\centerline{3. abc}} 
\setcounter{section}{3} 

command. It sets section heading in the centre of the page. But my first definition of 3rd section is being numbered as 3.8 instead of 3.1. Last dfinition of section 2 is numbered as 2.7. I want to reset the counters of definitions, theorems, examples for each section. How shuold i proceed? Please help!!!

  • Welcome to TeX.SE – Mico May 19 at 11:56
  • 4
    don't do this! \section*{\centerline{3. abc}} that is an unnumbered section (so does not reset the subsection counter) even though it will appear to the reader like a numbered section. You should not have formatting in that argument, use \section{abc} – David Carlisle May 19 at 11:57
  • Is there a reason why you don't do \setcounter{section}{3}\section{\centerline{abc}}? – DLichti May 19 at 11:58
  • @DLichti Shouldn't it be \setcounter{section}{2}\section... then? (\section does increment the counter...) – Ulrich Diez May 19 at 12:38
  • @UlrichDiez Sure, my main point was reversing \setcounter and \section. – DLichti May 19 at 12:47
2

It looks like you're engaging in quite a bit of low-level, "visual" formatting of your document. Now this is precisely what LaTeX is supposed to make unnecessary. The following, really old joke comes to mind: "Good Fortran programmers can program in Fortran in any language."

E.g., by issuing the instruction

\section*{\centerline{3. abc}}

to (a) center-set the sectioning header (here: "abc") while (b) placing a "dot" (aka "full stop") after the (c) manually-set section number, all the while using \section*, you engage in three distinct manual low-level formatting operations. As you must be aware, \section* does not increment the counter called section. And then you're surprised that the next definition's counter shows "3.8" rather than "3.1".

You will find writing documents in LaTeX far more enjoyable -- and you'll certainly be a lot more productive -- if you make a habit of distinguishing between low-level formatting-related matters (which, ideally, should be dealt with in the document's preamble) and matters of content and high-level, structural instructions, which is what the body of the document should be about.

E.g., something like the following might be useful for you.

enter image description here

\documentclass{article} % or some other suitable document class

%% 1. define a 'defn' environment
\usepackage{amsthm} % or 'ntheorem'
\newtheorem{defn}{Definition}[section] % subordinate 'defn' counter to 'section' counter

%% 2. place a dot after section number in section header
\makeatletter
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
   {\csname the#1\endcsname\space}%    default
   {\csname #1@cntformat\endcsname}}%  enable individual control
\def\section@cntformat{\thesection.\space} % section-level
\makeatother

%% 3. center-set section-level headers
\usepackage{sectsty}
\sectionfont{\centering}

\begin{document}

\setcounter{section}{2} % just for this example
\setcounter{defn}{7}

\begin{defn} \dots \end{defn}

\section{abc}
\begin{defn} \dots \end{defn}

\end{document}

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.