4

Consider the \section{abc}

the output will be like

1. abc

how can I change the '.' to '-' or vice versa. i.e.

2- abc
2
  • 3
    This is not necessarily true. What class are you using? A naive hack for the article class would be \makeatletter\renewcommand\thesection{\@arabic\c@section-}\makeatother ... but look at what that does to the Table of Contents (or if you also have subsections). It is therefore best to provide a minimal example (or here).
    – jon
    Commented Jun 18, 2013 at 5:58
  • I think the package titlesec can be of help.
    – koppor
    Commented Jan 25, 2018 at 6:52

3 Answers 3

15

Redefining \thesection doesn't help, because this will give wrong results when referencing a section number.

A “package free” solution is to access the \@seccntformat feature:

\documentclass{article}
\makeatletter
\renewcommand{\@seccntformat}[1]{%
  \csname the#1\endcsname\ --\ }
\makeatletter

\begin{document}
\section{Introduction}\label{sec:intro}

We're in section~\ref{sec:intro}.
\end{document}

enter image description here

2

You can use

\renewcommand{\thesection}{\arabic{section}-}

for that specific purpose. Note that you could also use roman, Roman, alph or Alph instead of arabic, and you can also customize further by adding \thechapter, for instance.

1
  • 5
    Unfortunately this is wrong. References to sections will contain the dash, which is certainly unwanted.
    – egreg
    Commented Jun 18, 2013 at 8:31
2

Without an additional knowledge about usage it may be simply (see probably corrected spacing):

\documentclass{article}

\def\thesection{\arabic{section}--\hspace{-1em}}
\begin{document}

\section{First}

\end{document}

enter image description here

2
  • 1
    Did you try doing \ref{sec:whatever} when the label is linked to a section?
    – egreg
    Commented Jun 18, 2013 at 8:25
  • @egreg I know, that ALL should be labelled "Achtung! Minen!", but without the requested usage I choose such a solution. Commented Jun 18, 2013 at 8:36

You must log in to answer this question.

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