1

The sections in my article have to be re-styled as follows :

\renewcommand{\section}[1]{\medskip \addtocounter{section}{1}\flushleft 
\textbf{\Roman{section}. \ #1}\medskip \setcounter{subsection}{0}
\setlength{\parindent}{5ex}}

However, I am unable to refer to my sections using \label and \ref commands. Referencing works fine is the above code is commented out. What could be the issue?

edit: The referencing needs to be in Roman too.

1
  • 1
    Use \refstepcounter{section} (this should automatically reset subsection. Also, \renewcommand{\thesection}{\Roman{section}} should be used for a consistent setting and referencing of sectional numbers.
    – Werner
    Sep 2, 2014 at 4:58

1 Answer 1

2

Rather than using

\addtocounter{section}{1}

use

\refstepcounter{section}

This increments the section counter by 1 and tells latex that the next reference created by \label{...} should refer to this counter.

Also, if you want the second numbers to always be in \Roman then you should use:

\renewcommand\thesection{\Roman{section}}

So now your section command becomes:

\renewcommand\thesection{\Roman{section}}
\renewcommand{\section}[1]{\medskip\refstepcounter{section}{1}%
       \flushleft\thesection. \ #1}\medskip%
       \setcounter{subsection}{0}\setlength{\parindent}{5ex}}

If, instead, you wanted \ref{...} to produce \thesection. \ #1 then this is more complicated as you have to set @currentlabel and @ is a protected character. For this you would need:

\renewcommand\thesection{\Roman{section}}
\makeatletter
\renewcommand{\section}[1]{\medskip\refstepcounter{section}{1}%
       \flushleft\thesection. \space #1}\medskip%
       \def\@currentlabel{\thesection. \space #1}
       \setcounter{subsection}{0}\setlength{\parindent}{5ex}}
\makeatletter

Btw, rather than restyling your section titles "by hand", you might find it easier to use the titlesec package.

7
  • That introduces the references, but they should be in \Roman font.. Sep 2, 2014 at 4:39
  • Take a look at the titlesec package.
    – Aradnix
    Sep 2, 2014 at 4:50
  • @Aradnix Look at the last line of my post!
    – user30471
    Sep 2, 2014 at 5:19
  • @ManojKumar If you want them in \Roman then you should use \renewcommand\thesection{\Roman{section}}. If you want the reference to be the value of \Roman{section}. \ #1 then edit your question to say this and I'll modify my answer to say how to do this.
    – user30471
    Sep 2, 2014 at 5:22
  • I saw your answer Andrew that's why I told @ManojKumar to check the package.
    – Aradnix
    Sep 2, 2014 at 5:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .