2

I've got a question following from a previous post answers on numbering paragraphs (Automatically assign a number to every paragraph).

I used the code that Alan provided, however it seems that I can't get any of the subsubsections numbered. Another thing is that the table of contents contains not only numbered sections but also a string of all paragraphs in each section (or it displays an error and does not compile.)

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{latexsym}
\usepackage{fullpage}
\usepackage{amsmath}
\usepackage{float}
\usepackage{indentfirst}
\usepackage[font=footnotesize,format=plain,labelfont=bf,up,textfont=it,up]{caption}
\setlength{\parindent}{0cm}
\usepackage{subfig}
\usepackage{booktabs}
\usepackage{appendix}
\pagenumbering{arabic}
\usepackage{verbatim}
\usepackage{setspace}
\usepackage{rotating}
\usepackage{subfig}
\usepackage{array}
\usepackage[english]{babel}
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage{subfig}

%to get para numbers in the margins

\usepackage{titlesec}
\usepackage{chngcntr}
\usepackage{lipsum} % for dummy text
\titleclass{\numpar}{straight}[\section]
\newcounter{numpar}
\renewcommand{\thenumpar}{\arabic{numpar}}
\counterwithout{numpar}{section} % from the chngcntr package
\titleformat{name=\numpar,page=odd}[leftmargin] {\normalfont %paragraph number for odd page
\bfseries\filleft}
{\thenumpar}{.5em}{}
\titleformat{name=\numpar,page=even}[leftmargin] {\normalfont %paragraph number for even page
\bfseries\filleft}
{\thenumpar}{.5em}{}
\titlespacing{\numpar}
{1pc}{0ex plus .1ex minus .2ex}{1pc}
\newcommand*{\np}{\numpar{}}
\usepackage[parfill]{parskip}
%evidence counter
\newcounter{evidence}
\newcommand{\ev}{%
        \bf{EV\stepcounter{evidence}}%
        \theevidence}
\begin{document}
\tableofcontents

\pagebreak
\section{A section}
\np  \lipsum[1] \marginpar{\ev}

\np \lipsum[5]

\subsection{A subsection}
\np \lipsum[2]

\subsubsection{A subsubsection}

\np \lipsum[3]\marginpar{\ev}

\end{document}
  • possible duplicate of margin numbering – Sigur Jan 3 '14 at 15:03
  • deleted previous question to avoid duplication -apologies – user43528 Jan 3 '14 at 15:11
  • I get “1.1 A subsection” – egreg Jan 3 '14 at 15:14
  • sorry meant subsubsection – user43528 Jan 3 '14 at 15:15
  • edited the question accordingly :) – user43528 Jan 3 '14 at 15:23
3

I don't know why you're doing in that complicated way.

\documentclass[12pt,a4paper]{article}

\usepackage{lipsum} % for dummy text
\usepackage{hyperref}

\newcounter{numpar}
\newcommand{\np}[1][]{%
  \par
  \refstepcounter{numpar}%
  \noindent
  \makebox[0pt][r]{%
    \makebox[0pt][l]{\textbf{\thenumpar}}%
    \qquad
  }%
  #1%
  \ignorespaces
}

%evidence counter
\newcounter{evidence}
\newcommand{\ev}{%
  \stepcounter{evidence}%
  \marginpar{\textbf{EV\theevidence}}%
}

\begin{document}

\tableofcontents

\clearpage

\section{A section}
\np  \lipsum*[1]\ev

\np \lipsum*[5]

\subsection{A subsection}
\np \lipsum*[2]

\subsubsection{A subsubsection}

\np[\label{last}] \lipsum*[3]\ev

An example of reference to a paragraph: \ref{last}

\end{document}

The optional argument to \np is for setting a label.

What's the problem with the \titleclass approach? You're inserting a level between sections and subsections. With this approach you don't, and also avoid bookmark and table of contents issues.

1

May be the syntax for lazy people of the linguex package is usfeul for you. Simply start the numbered paragraphs with \ex. commands (the dot is also part of the command):

\documentclass{article}    
\usepackage[margin=2cm]{geometry}    
\usepackage{linguex}    
\usepackage{lipsum} % for dummy text    
\begin{document}
\section{Section}
\ex.  \lipsum[1]\par 
% Note: for real text use blank lines instead \par 
\subsection{Subection}
\ex. \lipsum[2]\par
\subsubsection{Subsubsection}
\ex. \lipsum[3]\par
\ex. \lipsum[4]\par
\ex. \lipsum[5]\par
\end{document}

If you do not want the (n) format or the paragraph indentation, it is easy to adapt to your needs. A more elaborated example:

\documentclass[twocolumn]{article}    
\usepackage[columnsep=1.5cm,margin=1.5cm]{geometry}    
\usepackage{linguex}    
\usepackage{lipsum} % for dummy text    
\usepackage{textcomp}
\usepackage{indentfirst}
\usepackage{xcolor}
% Custom format of the number counter: 
\renewcommand{\ExLBr}{\color{orange}\sffamily\bfseries}
\renewcommand{\ExRBr}{:}
\setlength{\parindent}{0em} 
\setlength{\parskip}{\smallskipamount}%
\newcommand\np{\ex. \hspace{0em}}
% because these lenghts cannot be placed in preamble as is:
\newcommand\NumberInMargin{ 
\setlength{\Exindent}{-2em}% 
\setlength{\Exlabelsep}{2em}%
\setlength{\Exlabelwidth}{0em}%
\setlength{\Extopsep}{\smallskipamount}}
\begin{document}
\NumberInMargin
\section{Section}
\ex. \lipsum[1]\par 
\subsection{Subection}
\lipsum[30] % paragraph not numbered
\np \lipsum[2]\par
\subsubsection{Subsubsection}
\ex. \lipsum[4]\par
\ex. \lipsum[5]\par
\ex. \lipsum[6]\par 
     \lipsum[7]\par % paragraph not numbered
\ex. \lipsum[8]\par
\end{document}

One limitation could be if you want mix numbered and normal paragraphs, both with indentation only in the first line. Then, you can obtain numbered paragraph with indentation on the first line, but that after the \ex. paragraph, the next one without numeration suppress the indentation of the first paragraph (That have a lot of sense with the default format).

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.