2

I am creating a document for school and I am required to follow a specific format for numbering - that is: "1", then "1.", then "1.1." and so on. I am a Latex and Lyx beginner and haven't found a way to do this in this specific way (or in a simple enough way that I could follow). Should I use some package? Is there some preamble thing for this? Or would I have to do this manually?

Thank you in advance for your help.

Edit 1: Posting a MWE. I am using the article document class with manually changed section numbering to start from 0. Code:

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}

\makeatletter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands. \setcounter{section}{-1}

\makeatother

\usepackage{babel} \begin{document} \title{Title} \author{John Doe} \maketitle

\section{Preface}

\section{Characteristics}

\section{Division}

\subsection{Group A}

\subsubsection{A}

\subsubsection{B}

\paragraph{B1}

\section{Conclusion} \end{document}

Screenshot from Lyx: Lyx code screenshot

  • 1
    This highly depends on the documentclass you are using. Can you provide a minimal working example (MWE) such that we can help you there directly with the code? – Arne Jan 16 '23 at 21:49
  • I thought it would have something to do with documentclass, but I don't really know their differences. I will edit to post a MWE now but I will have to go to sleep afterwards. – MegaTortoise Jan 16 '23 at 22:09
  • Welcome to TeX.SE. – Mico Jan 17 '23 at 00:14
  • Thank you, after diving in it seems I will have to post here more often than anticipated. Once again, thanks for the answer and your help overall! – MegaTortoise Jan 17 '23 at 15:06

1 Answers1

1

A brute-force solution is to run

\renewcommand\thesubsection{\arabic{subsection}.}
\renewcommand\thesubsubsection{\thesubsection\arabic{subsubsection}.}
\renewcommand\theparagraph{\thesubsubsection\arabic{paragraph}.}

Unfortunately, this will create unwanted issues if you ever need to cross-reference subsection-, subsubsection-, and paragraph-level units. I therefore suggest you take the following, indirect or "circumspect" approach. I picked up this approach up some years ago, while reading the book "The LaTeX Companion" (2nd ed.).

enter image description here

\documentclass[english]{article}
\usepackage[T1]{fontenc}
%\usepackage[latin9]{inputenc} %% Are you absolutely sure about 'latin9'?!
\usepackage{babel}

\setcounter{secnumdepth}{4} % default is '3' \setcounter{tocdepth}{4}

%% Brute-force method: %\renewcommand\thesubsection{\arabic{subsection}.} %\renewcommand\thesubsubsection{\thesubsection\arabic{subsubsection}.} %\renewcommand\theparagraph{\thesubsubsection\arabic{paragraph}.}

%% Circumspect method: \makeatletter % the next 4 lines are straight from "The LaTeX Companion", 2nd ed. \def@seccntformat#1{@ifundefined{#1@cntformat}% {\csname the#1\endcsname\quad} % default {\csname #1@cntformat\endcsname} % enable individual control }

\renewcommand\thesubsection{\arabic{subsection}} \newcommand{\subsection@cntformat}{\thesubsection.\quad} \newcommand{\subsubsection@cntformat}{\thesubsubsection.\quad} \newcommand{\paragraph@cntformat}{\theparagraph.\quad} \makeatother

\begin{document} \setcounter{section}{-1} \section{Preface} \section{Characteristics} \section{Division}

\subsection{Group A}

\subsubsection{A} \label{sec:A} \subsubsection{B} \label{sec:B}

\paragraph{B1} \label{sec:B1}

\section{Conclusion}

Cross-references to subsubsections \ref{sec:A} and \ref{sec:B} and to parapraph \ref{sec:B1}. \end{document}

Mico
  • 506,678
  • This does exactly what I wanted, thank you. I am still a beginner though, and I would like to be able to better understand/ eventually make these kinds of things myself. I found some documentation, tutorials... but none of it is really unified. Would you recommend any specific place/ textbook I should start to improve my knowledge?

    (About the 'latin9', I am not sure at all, I don't really understand the settings, Lyx put that in the source code. Should I not use 'inputenc' at all?)

    – MegaTortoise Jan 17 '23 at 15:10
  • @MegaTortoise - Glad to learn that my answer was useful. :-) About general learning resources for TeX: Please see the posting What are good learning resources for a LaTeX beginner? By now, the default input encoding for LaTeX has been UTF8 for several years, and I believe that lyx's built-in editor also employs UTF8 input encoding. Since \usepackage[utf8]{inputenc} is the default, the statement is redundant and may as well be omitted. – Mico Jan 17 '23 at 15:24