0

I am trying to apply the answer to this question in Overleaf. I want to number my lines but I don't want the chapter/section titles to be numbered. I'm running into errors when applying the answer. Here is my preamble from Overleaf, this is before trying to adjust the line numbering section in the preamble to stop numbering the titles.

I'm including the majority of my preamble because I almost always forget relevant parts when submitting questions to this forum. I'm also fairly new to Latex.

\documentclass[11pt,twoside,openany]{book}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\setlength\parindent{0.5in}
\usepackage[a4paper,width=150mm,top=1in,bottom=1in,bindingoffset=6mm]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{fancyhdr}
\pagestyle{fancy}
% header
\fancyhead{}
\fancyhead[LO,LE]{Running Title}
\fancyhead[RO,RE]{Chapter \thechapter}
% footer
\fancyfoot{}
\fancyfoot[CE,CO]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\usepackage{setspace}
% formatting for tables
\usepackage{multirow, makecell}
\usepackage{multicol}
% front matter
% table of contents
% http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/tocloft/tocloft.pdf
\usepackage{tocloft}
\renewcommand{\contentsname}{\hfill\bfseries\LARGE \MakeUppercase{Table of Contents}\hfill}   
\renewcommand{\cftaftertoctitle}{\hfill}
% this is to make a command to make certain sections not appear in the TOC
\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}
% list of figures
\renewcommand{\listfigurename}{\hspace*{\fill}\bfseries\LARGE \MakeUppercase{List of Figures}}
\renewcommand{\cftafterloftitle}{\hspace*{\fill}}
% list of tables
\renewcommand{\listtablename}{\hspace*{\fill}\bfseries\LARGE \MakeUppercase{List of Tables}}
\renewcommand{\cftafterlottitle}{\hspace*{\fill}}
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}
\usepackage{titlesec}
%\titleformat{\chapter}[display]{\filcenter\normalfont\LARGE\bfseries}{Chapter         \thechapter}{1em}{\LARGE}
\titleformat{\chapter}[display]{\filcenter\normalfont\LARGE\bfseries}{\chaptertitlename\@ \thechapter}{1em}{\LARGE}
\titlespacing*{\chapter}{0pt}{*12}{*8}
\titleformat*{\section}{\filcenter\bfseries\Large}
\titleformat*{\subsection}{\filcenter\large\bfseries}
\titleformat*{\subsubsection}{\filcenter\normalsize\bfseries\itshape}
%\titleformat*{\paragraph}{\normalsize\bfseries}
%\titleformat*{\subparagraph}{\normalsize\bfseries}

\usepackage[style=apa,sorting=ynt]{biblatex}
\addbibresource{references.bib}
\usepackage{amsmath}
\usepackage[mathscr]{euscript}% use for script letters
\DeclareMathOperator*{\argmax}{arg\,max}% use for argmax
% other material in the preamble
\usepackage{lipsum}
\renewcommand\cftchapdotsep{\cftdotsep}
\renewcommand\cftchapleader{\cftdotfill{\cftchapdotsep}}


\usepackage[pagewise]{lineno}% Enable numbering of text and display math
\linenumbers\relax % Commence numbering lines
%-------------------------------------------------------------------

\begin{document}
    \chapter{This is the first chapter}
        \section{This is the first section of the first chapter}
\end{document}

I have the lines for initiating the line numbering at the very end of my preamble. This compiles fine, but I don't want the chapter/section titles to be numbered.

The accepted answer in the question I mentioned suggests including the following in the preamble for the line numbering.

\usepackage{etoolbox,lineno}% http://ctan.org/pkg/{etoolbox,lineno}
\makeatletter
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\@startsection}{\@ifstar}{\nolinenumbers\@ifstar}{}{}
\patchcmd{\@xsect}{\ignorespaces}{\linenumbers\ignorespaces}{}{}
\makeatother
\linenumbers

Doing so gave the following errors in Overleaf...

Option clash package for etoolbox and Missing \begin{document}

It was then recommended that I adjust the first line to be

\usepackage{etoolbox}
\usepackage[pagewise]{lineno}

which just prevented the latex file from compiling at all.

There may be something else from my preamble conflicting with the etoolbox package. Hopefully I can get help with these errors.

0

The solution for that question is specifically for when titlesec nor hyperref is used, but your preamble does load titlesec.

It should be enough to add \nolinenumbers to your existing \titleformat for the chapter and sectional headings:

\titleformat{\chapter}[display] 
  {\filcenter\normalfont\LARGE\bfseries\nolinenumbers}
  {\chaptertitlename\@ \thechapter}{1em}{\LARGE}
\titleformat*{\section}{\filcenter\bfseries\Large\nolinenumbers}
...similarly for \subsection, \subsubsection...
1
  • This works, thanks. I will be adding hyperref later, will this cause problems?
    – WnGatRC456
    Sep 30 '20 at 14:44

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.