# There is a space between label and punctuation/comma when I used \ref{label} command

I am writing a thesis using my institution's template. However, when I use \ref{label} command, there is a spacing after the label and punctuation/comma. My working is as follows:

\makeatletter
\let\my@xfloat\@xfloat
\makeatother

\documentclass[oneside,12pt,a4paper]{book}
%\documentclass[12pt,a4paper]{book}
\usepackage{UTMThesis, enumerate, amsfonts, longtable, qtree, etoolbox, array, rotating, pgf, tikz, tikz-cd, algorithm, csquotes}

\makeatletter
\def\@xfloat#1[#2]{
\my@xfloat#1[#2]%
\def\baselinestretch{1}%
\@normalsize \normalsize
}
\makeatother

\allowdisplaybreaks
\usetikzlibrary{arrows, matrix, positioning, shapes, shapes.geometric, calc, intersections, decorations.pathreplacing}
\newcommand{\tikznode}[2]{\relax
\ifmmode%
\tikz[remember picture,baseline=(#1.base),inner sep=0pt] \node (#1) {$#2$};
\else
\tikz[remember picture,baseline=(#1.base),inner sep=0pt] \node (#1) {#2};%
\fi}
\let\openbox\relax
\let\iint\relax
\let\iiint\relax
\let\iiiint\relax
\let\idotsint\relax

\newcommand*{\qed}{\hfill\ensuremath{\square}}

%-------------------------------------------------------------
\usepackage{cite}                       % change  cite from [1,2,3] to [1-3] etc for number system
\makeatletter                           % change from
\renewcommand{\@biblabel}[1]{#1.}     % [1] to 1. etc
\makeatother                            % in list of references
%-----------------------------------------------------------
\setlength{\voffset}{-2.1cm}
\setlength{\hoffset}{-.4cm}
%--------------------------------------------------------
\font\fiverm=cmr5
%\input{Pictex.tex} % using pictex
%---------------------------------------------------------
%\pagestyle{plain}
%-------------------------------------------------------
\usepackage{fancyhdr}
\pagestyle{fancy}
\lfoot{}
\cfoot{\vspace{-.35cm}\thepage}  %
\rfoot{}
%-------------------------------------------------------
\begin{document}
\frontmatter

\chapter{INTRODUCTION}

\section{Background and motivation}
\label{section:background}

In Section \ref{section:background}, we talked about...

\backmatter
\end{document}


that produces:

How can I fix this?

• The problem you've encountered would appear to be caused by some code in UTMThesis.sty. Please tell us more about this style file. Is it available online? – Mico Feb 7 at 4:59
• There's probably a \renewcommand{\thesection}{\thechapter.\arabic{section}\quad} within UTMThesis.sty. Instead the style should use \@seccntformat to set the space in the section counter formatting; not set it as part of the representation. – Werner Feb 7 at 5:07

I was able to replicate the issue when using UTMThesis.sty from How to write the definition of each term in an equation with pointing arrows? That style file has

\renewcommand{\thesection} % space between sect. etc.
{\thechapter.\arabic{section}\hspace{.12in}}
\renewcommand{\thesubsection}
{\thesection\hspace{-.3cm}.\arabic{subsection} \hspace{-.135cm}}


Including the space within the \thesection representation makes it carry through to any \label and eventually the \ref as well. So, instead you'll need to redefine \thesection to the following:

\renewcommand{\thesection}{\thechapter.\arabic{section}}
\renewcommand{\thesubsection}{\thesection.\arabic{subsection}}


You can increase the gap between the sectional unit number and title, adjust it via \@seccntformat:

\makeatletter

The default space is \quad (equivalent to \hspace{1em}).