5

Is it possible to number sections by binary numbers, starting at 0? So \section{First Section} would render as "0. First Section", and the next instance would render "1. Second Section" and the third, "10. Third Section"?

  • Related/duplicate: Binary arithmetic (for your specific applications, the answer which uses the the fmtcount package seems the most appropriate. – Alan Munn Jun 8 at 17:06
8

Sure.

\documentclass{article}

\usepackage{expl3}

\ExplSyntaxOn
    \cs_set:Npn \thesection {\int_to_bin:n{\value{section}-1}}
\ExplSyntaxOff

\begin{document}

\section{one}

\section{two}

\section{three}

\end{document}

MWE output

Note that I only changed the displayed number here, so the section counter still has the value 1 for the first section, we only print 0. If you want the section to "really" have the number 0, you need to remove the -1 from the definition of \thesection and set the counter to -1 at the start of the document.

11

The fmtcount package provides a simple way to get the binary numbers. To begin counting at zero you need to set the section counter initially to -1. You can also pad the values with zeroes if you wish.

\documentclass{article}
\usepackage{fmtcount}
\renewcommand{\thesection}{\binary{section}.}
\setcounter{section}{-1}% To begin at 0

\begin{document}

\section{First section}
\section{Second section}
\section{Third section}
\section{Fourth section}
\section{Fifth section}
\renewcommand{\thesection}{\padzeroes[4]\binary{section}}
\setcounter{section}{-1}
\section{First section}
\section{Second section}
\section{Third section}
\section{Fourth section}
\section{Fifth section}
\end{document}

sample output

  • 1
    This has the big disadvantage of not being expandable. – egreg Jun 8 at 17:54

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.