Take the 2-minute tour ×
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.

I am using article class, and by default, the numbers of the sections, subsections appear like 1 section, 2 section in time I want them to appear like 1. section, 2. section (with dots).

I have redefined the format of my section, subsection, etc. as follows:

\renewcommand\thesection{\arabic{section}.}
\renewcommand\thesubsection{\arabic{section}.\arabic{subsection}.}

because I wanted . after the number of the section and the subsection. Fortunately, I got the format that I want, but now I have another problem, when I use the cross-reference to the section or the subsection, I got extra . after the reference, like: as we have seen in section 1.., or section 2.. it is unwanted. How can I get rid of this extra .? Is there anyway to change or redefine the appearance of the \ref?

share|improve this question

3 Answers 3

up vote 4 down vote accepted

My answer to can i change refs output can be adjusted for this:

\documentclass{article}

\renewcommand\thesection{\arabic{section}.}
\renewcommand\thesubsection{\thesection\arabic{subsection}.}
\renewcommand\thesubsubsection{\thesubsection\arabic{subsubsection}.}

\makeatletter
\renewcommand{\p@section}{\arabic{section}\expandafter\@gobble}
\renewcommand{\p@subsection}{\thesection\arabic{subsection}\expandafter\@gobble}
\renewcommand{\p@subsubsection}{\thesubsection\arabic{subsubsection}\expandafter\@gobble}
\makeatother

\begin{document}

\section{test}\label{test}
\subsection{subtest}\label{subtest}
\subsubsection{subsubtest}\label{subsubtest}


See section~\ref{test} and subsection~\ref{subtest} and subsubsection~\ref{subsubtest}!

\end{document}

Note that this is a little bit of a hack.

You could also adjust the sectioning commands using titlesec instead.

share|improve this answer
1  
This is not the correct way to do that simple thing. It's true that titlesec can be used, but the formatting of the (sub)section number is under the control of \@seccntformat. –  egreg Jul 6 '11 at 9:31
    
@egreg: I thought that there should be a better way to do it. Please also see the original question (this is a follow-up) Can I change \ref's output? and consider answering it as well. Thanks! –  Martin Scharrer Jul 6 '11 at 9:38
    
That is correct. –  egreg Jul 6 '11 at 9:48
    
Thank you Martin. It works. –  Mara Jul 6 '11 at 14:04
    
@Mara: actually egreg's solution is better. Give it a try. –  Martin Scharrer Jul 6 '11 at 14:06

See the relevant UK TUG FAQ

\makeatletter
\renewcommand{\@seccntformat}[1]{\csname the#1\endcsname.\quad}
\makeatother
share|improve this answer

use the class scrartcl instead. It has an optional argument for this:

\documentclass[numbers=enddot]{scrartcl}
share|improve this answer
    
+1 for using KOMA-Script –  Tobi Jul 6 '11 at 11:19

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.