TransWikia.com

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

TeX - LaTeX Asked on August 10, 2021

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
letmy@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]%
    defbaselinestretch{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}
letopenboxrelax
letiintrelax
letiiintrelax
letiiiintrelax
letidotsintrelax

newcommand*{qed}{hfillensuremath{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}  
%--------------------------------------------------------
fontfiverm=cmr5 
%input{Pictex.tex} % using pictex
%---------------------------------------------------------
%pagestyle{plain}
%-------------------------------------------------------
usepackage{fancyhdr}
pagestyle{fancy}
lhead{}
chead{}
rhead{}
lfoot{}  
cfoot{vspace{-.35cm}thepage}  % 
rfoot{} 
renewcommand{headrulewidth}{0pt}
%-------------------------------------------------------
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:

enter image description here

How can I fix this?

One Answer

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} 
  {thesectionhspace{-.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
renewcommand{@seccntformat}[1]{csname the#1endcsnameqquad}
makeatother

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

Correct answer by Werner on August 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP