6

I want to include three sections in my document, but I want the section numbers to be 3, 5 and 6. Can I somehow give predefined values to sections?

\documentclass[11pt]{article}
\begin{document}

\section{Third}
\section{Fifth}
\section{Sixth}

\end{document}

The above code will as usual create 3 sections numbered 1, 2, 3. Any way to change them?

1
  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.
    – Louis
    Oct 22 '16 at 14:01
6

Use a couple of \setcounter intructions, operating on the counter variable called section.

enter image description here

\documentclass[11pt]{article}
\begin{document}

\setcounter{section}{2} % so that the next section is numbered "3"
\section{Third}

\setcounter{section}{4} % so that the next section is numbered "5"
\section{Fifth}
\section{Sixth} % no need to set the 'section' counter variable for this section 

\end{document}
0
4

Expand this to your needs adding more \or<number> bits as needed.

\documentclass{article}

\makeatletter
\newcommand{\fancynumbering}[1]{\expandafter\@fancynumbering\csname c@#1\endcsname}
\newcommand{\@fancynumbering}[1]{%
  \ifcase#1\or3\or5\or6\else\@ctrerr\fi
}
\makeatother

\renewcommand{\thesection}{\fancynumbering{section}}

\begin{document}

\section{Third}
\section{Fifth}
\section{Sixth}

\end{document}

enter image description here

A possibly cleaner interface:

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\setupfancycounter}{mm}
 {
  \clist_const:cn { c_typos_#1_clist } { #2 }
 }
\DeclareExpandableDocumentCommand{\fancynumbering}{mm}
 {
  \int_compare:nTF
   { \int_use:c { c@#2 } > \clist_count:c { c_typos_#1_clist } }
   { \use:c { @ctrerr } }
   { \clist_item:cn { c_typos_#1_clist } { \int_use:c { c@#2 } } }
 }
\ExplSyntaxOff

\setupfancycounter{fancynumbers}{3,5,6}
\renewcommand{\thesection}{\fancynumbering{fancynumbers}{section}}

\begin{document}

\section{Third}
\section{Fifth}
\section{Sixth}
\section{Oops}

\end{document}

The last section will raise an error.

There's an easier method, but the above ones have the advantage of using the standard markup.

\documentclass{article}

\newcommand{\fixedsection}[1]{%
  \setcounter{section}{#1}%
  \addtocounter{section}{-1}%
  \section
}

\begin{document}

\fixedsection{3}{Second}

\fixedsection{5}{Third}

\fixedsection{6}{Sixth}

\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.