# Keeping periods after section numbers but not when referencing sections

I know this has been discussed before, and I am using some of the suggestions from other posts, but I am having a hard time implementing the suggestions into my own code. This is a snippet from my .cls file:

% section heading formats
\def\section{\@startsection {section}{1}{\z@}%
{-3.5ex \@plus -1ex \@minus -.2ex}%
{2.3ex \@plus.2ex}%
{\normalfont\large\bfseries}}
\def\subsection{\@startsection{subsection}{2}{\z@}%
{-3.25ex\@plus -1ex \@minus -.2ex}%
{1.5ex \@plus .2ex}%
{\normalfont\normalsize\bfseries}}
\def\subsubsection{\@startsection{subsubsection}{3}{\z@}%
{-3.25ex\@plus -1ex \@minus -.2ex}%
{1.5ex \@plus .2ex}%
{\normalfont\normalsize\itshape}}
% redefine section, figure etc. format
\def\thesection       {\arabic{section}} **%Note: removed period**
\def\thesubsection    {\thesection\arabic{subsection}.}
\def\thesubsubsection {\thesubsection\arabic{subsection}.}
\def\figurename{Fig.}
\def\tablename{Table}

**%Note: I added this so that periods still remain on section titles but not when being referred inline**
\usepackage{tocloft}
\usepackage{titlesec}
\titleformat{\section}
{\normalfont\bfseries}{\thesection.}{0.5em}{}
\renewcommand\cftsecaftersnum{.}
\renewcommand\thesection{\arabic{section}}
\renewcommand\thesubsection{\thesection.\arabic{subsection}}


The section of code under the second note is what I got from a previous thread, and it works beautifully to remove the period from the references but not the section titles, the problem is I lose the smaller size of the subtitles.

I feel like I'm really close, but I've been struggling to keep both features - please let me know if there is any more code or information I can provide.

edit: entire .cls file

%%% Partnership for Advanced Computing in Europe
%%%   www.prace-ri.eu
%%%
%%% LaTeX document class for a PRACE-RI whitepaper.
%%%
%%% (c) CSC - IT Center for Science Ltd.
%%%   author: Martti Louhivuori (martti.louhivuori@csc.fi)
%%%
%%% Requires: LaTeX2e
%%%           geometry, graphicx, ifthen, booktabs
%%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{prace}[2013/03/26 PRACE-RI Whitepaper class]

\DeclareOption{onecolumn}{\OptionNotUsed}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax

% A4: 210x297mm - 20mm margins
\RequirePackage{geometry}
\geometry{text={170mm,257mm}, centering}
\RequirePackage{graphicx}
\RequirePackage{ifthen}
\RequirePackage{booktabs}

% page numbering
\pagenumbering{arabic}
%\pagestyle{empty}
% default font
\renewcommand{\normalsize}{\fontsize{10}{11}\selectfont}

% default values
\def\projectname{}
\def\authortel{+0-000-000-0000}
\def\authorfax{+0-000-000-0000}
\def\authoremail{author@example.com}

% internal counters
\newcounter{praceauth}
\setcounter{praceauth}{0}
\renewcommand\thepraceauth{\alph{praceauth}}
\newcounter{praceaffi}
\setcounter{praceaffi}{0}
\renewcommand\thepraceaffi{\alph{praceaffi}}
\newcounter{pracetmp}
\setcounter{pracetmp}{0}
\renewcommand\thepracetmp{\alph{pracetmp}}

% project ID & author contact details

% tag corresponding author
\newif\if@iscorresponding
\@iscorrespondingfalse
\newif\if@hascorresponding
\@hascorrespondingfalse
\newcommand\corresponding[0]{\@iscorrespondingtrue\@hascorrespondingtrue}
% corresponding author footnote
\long\def\authorfootnote{%
\def\thefootnote{\fnsymbol{footnote}}%
\csname c@\@mpfn\endcsname 1\relax%
\xdef\@thefnmark{\thempfn}%
\@footnotetext}
% corresponding author contact detail footnote
\def\authorcontact{%
\authorfootnote{Corresponding author.\\%
\indent\hspace{1ex}
tel. \authortel{}\hspace{1ex}
fax. \authorfax{}\hspace{1ex}
e-mail. \authoremail{}}
}

% tmp flag
\newif\if@praceflag
\@praceflagfalse

% convert integers to letters
\def\csvitoalist{}
\newcommand\csvitoa[1]{
\def\csvitoalist{}
\@for\name:=#1\do{
\setcounter{pracetmp}{\name}
\if@praceflag
\edef\csvitoalist{\csvitoalist,\thepracetmp}
\else
\edef\csvitoalist{\thepracetmp}
\@praceflagtrue
\fi}
\@praceflagfalse
\csvitoalist
}

% store author definitions for later use
\def\authorlist{}
\def\tmpname{}
\renewcommand\author[2][a]{%
%
\def\alfalist{}
\@for\name:=#1\do{
\setcounter{pracetmp}{\name}
\if@praceflag
\edef\alfalist{\alfalist,\thepracetmp}
\else
\edef\alfalist{\thepracetmp}
\@praceflagtrue
\fi}
\@praceflagfalse
%
%   \def\alfalist{\csvitoa{#1}}
%
\def\tmpname{#2}
\if@iscorresponding
\edef\tmpname{\tmpname{}${}^{\alfalist{},*}$}
\else
\edef\tmpname{\tmpname{}${}^{\alfalist}$}
\fi
\ifnum \c@praceauth >\z@
\edef\authorlist{\authorlist{}, \tmpname{}}
\else
\edef\authorlist{\tmpname{}}
\fi
\@iscorrespondingfalse
}
% store affiliation definitions for later use
\def\affiliationlist{}
\newcommand\affiliation[2][a]{%
\def\tmpname{{${}^{\thepraceaffi}$#2}}
\ifnum \c@praceaffi >\@ne
\edef\affiliationlist{\affiliationlist{},\tmpname{}}
\else
\edef\affiliationlist{\tmpname{}}
\fi%
}
% output affiliation list
\newcommand\affiliationblock[0]{%
\@for\name:=\affiliationlist\do{\name\\}}

% title block
\renewcommand{\maketitle}{%
\newpage
\noindent\begin{minipage}{3cm}
%\includegraphics[width=3cm]{prace-logo}
\end{minipage}
\begin{minipage}{11cm}
\centering%
%Available on-line at www.prace-ri.eu\\\vspace{1em}
%{\large\bfseries Partnership for Advanced Computing in Europe}
\end{minipage}
\begin{minipage}{3cm}
\end{minipage}\\
\null
\vskip 2em%
\begin{center}%
\let \footnote \thanks
{\LARGE \@title \par}%
\vskip 1.5em%
{\large
\lineskip .5em%
\begin{tabular}[t]{c}%
\authorlist
\end{tabular}\par}%
\vskip 1em%
\affiliationblock
\if@hascorresponding
\authorcontact
\else
\@latex@warning{Corresponding author is undefined}
\fi
\end{center}%
\par
\vskip 1.5em%
}

\def\section{\@startsection {section}{1}{\z@}%
{-3.5ex \@plus -1ex \@minus -.2ex}%
{2.3ex \@plus.2ex}%
{\normalfont\large\bfseries}}
\def\subsection{\@startsection{subsection}{2}{\z@}%
{-3.25ex\@plus -1ex \@minus -.2ex}%
{1.5ex \@plus .2ex}%
{\normalfont\normalsize\bfseries}}
\def\subsubsection{\@startsection{subsubsection}{3}{\z@}%
{-3.25ex\@plus -1ex \@minus -.2ex}%
{1.5ex \@plus .2ex}%
{\normalfont\normalsize\itshape}}
% redefine section, figure etc. format
\def\thesection       {\arabic{section}} %Josh: removed period
\def\thesubsection    {\thesection\arabic{subsection}.}
\def\thesubsubsection {\thesubsection\arabic{subsection}.}
\def\figurename{Fig.}
\def\tablename{Table}

%Josh's Note: I added this so that periods still remain on section titles but not when being referred inline
\usepackage{tocloft}
\usepackage{titlesec}
\titleformat{\section}
{\normalfont\bfseries}{\thesection.}{0.5em}{}
\renewcommand\cftsecaftersnum{.}
\renewcommand\thesection{\arabic{section}}
\renewcommand\thesubsection{\thesection.\arabic{subsection}}

% add horisontal lines before and after the abstract
\renewenvironment{abstract}%
{\noindent\rule{\textwidth}{0.1pt}
\small
\noindent{\bfseries \abstractname}
\quotation}%
{\vspace{0em}{\small \projectname}\\ %TOOK OUT Project ID after \small
\noindent\rule{\textwidth}{0.1pt}}
% no indentation for quotations
\renewenvironment{quotation}%
{\list{}{%
\listparindent 0.0em
\itemindent    \listparindent
\rightmargin   \leftmargin
\parsep        \z@ \@plus\p@}%
\item\relax}
{\endlist}

% add space either after table caption or before figure caption
\newif\if@withintable
\@withintablefalse
\newif\if@withinfigure
\@withinfigurefalse
\renewenvironment{figure}
{\@withinfiguretrue\@float{figure}}
{\end@float\@withinfigurefalse}
\renewenvironment{figure*}
{\@withinfiguretrue\@dblfloat{figure}}
{\end@dblfloat\@withinfigurefalse}
\renewenvironment{table}
{\@withintabletrue\@float{table}}
{\end@float\@withintablefalse}
\renewenvironment{table*}
{\@withintabletrue\@dblfloat{table}}
{\end@dblfloat\@withintablefalse}
\setlength\abovecaptionskip{10\p@}
\setlength\belowcaptionskip{10\p@}
\long\def\@makecaption#1#2{%
\if@withinfigure
\vskip\abovecaptionskip
\fi
{\small #1. #2\par}
\if@withintable
\vskip\belowcaptionskip
\fi}

% ref.number in References
\def\@biblabel#1{\indent#1.}


Edited code that keeps font size consistent, removes the decimal from references while keeping it in section titles, but also removes the decimal after the section number in subsection titles (i.e. 2.3. becomes 23.):

\def\thesection       {\arabic{section}} %Josh: removed period
\def\thesubsection    {\thesection\arabic{subsection}}
\def\thesubsubsection {\thesubsection\arabic{subsection}}
\def\figurename{Fig.}
\def\tablename{Table}

\usepackage{tocloft}
\renewcommand{\cftsecaftersnum}{.}
\renewcommand{\cftsubsecaftersnum}{.}
\renewcommand{\cftsubsubsecaftersnum}{.}

• if your only remaining problem is the size of the subsection titles, you could try substituting \small for \normalsize in the appropriate definition. (not tested, not without a compilable example.) – barbara beeton Oct 31 '17 at 20:09
• This does not work - the problem is happening after that point when I add the new section of code under the second Note, which is why I am not getting a difference between '\large' and '\normalsize'. Changing '\normalsize' to '\small' does not fix this issue. Do you see what I mean? I have edited in the entire cls file if it helps to provide a compilable example. – user8728930 Oct 31 '17 at 20:18
• @user8728930: tocloft and titlesec, together? Really? Also: You should not do too much redefinitions of \thesection etc. You have to change \p@section rather. – user31729 Oct 31 '17 at 20:27
• Hello @ChristianHupfer, thank you for your comment, but I am having a hard time finding it constructive - I am fairly new to LaTeX. Why is it inappropriate to have tocloft and titlesec together? but more importantly, can you please specify how I would have to change \p@section to achieve my desired outcome? I cannot find much on this. Thank you very much. – user8728930 Oct 31 '17 at 20:37
• @user8728930: tocloft and titlesec and especially titletoc do not go well together. I don't use titlesec any longer. And sorry, but if you are fairly new to LaTeX, it is quite ambitious to write a class. – user31729 Oct 31 '17 at 20:40

Here's how you can add a . to the end of the sectional number within the heading:

\makeatletter
\def\thesection       {\arabic{section}}
\def\thesubsection    {\thesection\arabic{subsection}}
\def\thesubsubsection {\thesubsection\arabic{subsubsection}}
\makeatother

\usepackage{tocloft}
\renewcommand{\cftsecaftersnum}{.}
\renewcommand{\cftsubsecaftersnum}{.}
\renewcommand{\cftsubsubsecaftersnum}{.}


All the periods are removed from the \the<secunit> counter representations and updated in the sectional counter formatting macro \@seccntformat. This way you can still use \label-\ref without concern about a period following you around. The addition of tocloft ensures that a . is placed after every unit within the ToC:

\documentclass{article}

\makeatletter
\def\thesection       {\arabic{section}}
\def\thesubsection    {\thesection\arabic{subsection}}
\def\thesubsubsection {\thesubsection\arabic{subsubsection}}
\makeatother

\usepackage{tocloft}
\renewcommand{\cftsecaftersnum}{.}
\renewcommand{\cftsubsecaftersnum}{.}
\renewcommand{\cftsubsubsecaftersnum}{.}

\usepackage{lipsum}\sloppy% Just for this example

\begin{document}

\tableofcontents

See \ref{sec:first}, \ref{subsec:first} and \ref{subsubsec:first}.

\section{First section}\lipsum[1-10]\label{sec:first}
\subsection{First subsection}\lipsum[11-20]
\subsubsection{First subsubsection}\lipsum[21-30]
\subsubsection{Second subsubsection}\lipsum[31-40]
\subsubsection{Third subsubsection}\lipsum[41-50]
\subsubsection{Last subsubsection}\lipsum[1-10]

\subsection{Second subsection}\lipsum[11-20]\label{subsec:first}
\subsubsection{First subsubsection}\lipsum[21-30]
\subsubsection{Second subsubsection}\lipsum[31-40]
\subsubsection{Third subsubsection}\lipsum[41-50]
\subsubsection{Last subsubsection}\lipsum[1-10]

\subsection{Third subsection}\lipsum[11-20]
\subsubsection{First subsubsection}\lipsum[21-30]\label{subsubsec:first}
\subsubsection{Second subsubsection}\lipsum[31-40]
\subsubsection{Third subsubsection}\lipsum[41-50]
\subsubsection{Last subsubsection}\lipsum[1-10]

\subsection{Last subsection}\lipsum[11-20]
\subsubsection{First subsubsection}\lipsum[21-30]
\subsubsection{Second subsubsection}\lipsum[31-40]
\subsubsection{Third subsubsection}\lipsum[41-50]
\subsubsection{Last subsubsection}\lipsum[1-10]

\end{document}


If you want to condition on only placing . with specific sectional units, you can define unit-specific formatting macros. For example, having . only with \subsection (not \section nor \subsubsection):

\makeatletter
\def\thesection       {\arabic{section}}
\def\thesubsection    {\thesection\arabic{subsection}}
\def\thesubsubsection {\thesubsection\arabic{subsubsection}}
\renewcommand{\@seccntformat}[1]{\csname #1cntformat\endcsname}
\makeatother

\usepackage{tocloft}
\renewcommand{\cftsecaftersnum}{}
\renewcommand{\cftsubsecaftersnum}{.}
\renewcommand{\cftsubsubsecaftersnum}{}


• thank you very much for the thoughtful response. I implemented your suggestions to my code (I edited in the updated code at the bottom of my post) and it worked beautifully - I'm getting a decimal after the section number but not when I reference the section, and the font size is consistent - but now I am missing a decimal between the section number and subsection number for subsection titles (i.e. section 2.3. is now 23.) Would you be able to suggest how to keep the decimal after the section number for subsections? Thank you. – user8728930 Nov 1 '17 at 22:08
• @user8728930: So, for \subsections, you currently have 23. in the text and 23 in your reference. And you want 2.3. in the text and 2.3 in the reference, correct? – Werner Nov 1 '17 at 22:28
• Yes, this is exactly what I am going for - the last piece seems to be having 2.3. in the text while keeping all the other properties the same - thank you for checking in with me again – user8728930 Nov 2 '17 at 3:09
• @user8728930: For that you don't have to redefine any of \thesection, \thesubsection and \thesubsubsection. If you must, use \def\thesection{\arabic{section}} \def\thesubsection{\thesection.\arabic{subsection}} \def\thesubsubsection{\thesubsection.\arabic{subsubsection}}. – Werner Nov 2 '17 at 3:40
• @FiboKowalsky: Each sectional unit (usually \section, \subsection, \subsubsection, ...) has their numbers formatted for setting within the text using the command \@seccntformat{section} (for \section), \@seccntformat{subsection} (for \subsection), ... Based on the definition of \@seccntformat, it prints \thesection (for \section), \thesubsection (for \subsection), ... followed by a \quad (a space of width 1em). My redefinition follows exactly this approach, but inserts a . before setting the \quad, thereby adding the required period in the output. – Werner Jan 30 '18 at 15:46