# Why am I having a space to the next word? How to fix it?

I have what I would like to think, a simple question.

I have the following tex code:

\begin{description}%[style=nextline]
\item [Category\label{desc:category}] blablabla
\item [Profile\label{desc:profile}] blabla (\nameref{desc:category}) blabla.
\end{description}


The result is something like this:

Category blablabla

Profile blabla (Category 'bunch of spaces') blabla.

Why do I have these spaces after Category reference I made?

• Welcome to TeX.SE! Please tell us how, i.e., with which options and in which order, you load the hyperref and/or nameref packages.
– Mico
Apr 19, 2017 at 16:53
• Welcome to TeX.SX! My guess is that the redefinition of \label or of \nameref introduces spurious spaces because the lines of the definition are not properly terminated with %. But we can only tell for sure if you provide a complete small document showing everything from \documentclass to \end{document}. Apr 19, 2017 at 16:54
• – Werner
Apr 19, 2017 at 16:55

## 3 Answers

To replicate the issue you're reporting, it turns out to be necessary to load the enumitem package in addition to the hyperref (or nameref) package. E.g., the following MWE

\documentclass{article}
\usepackage{enumitem}
\usepackage[colorlinks]{hyperref} % or: \usepackage{nameref}

\begin{document}
\begin{description}
\item[Category\label{desc:category}] blablabla
\item[Profile\label{desc:profile}] blabla
(\nameref{desc:category}) blabla
\end{description}
\end{document}


produces this output:

In short, it looks like you've come across a rather significant and quite unfortunate conflict between the enumitem and hyperref packages. (Christian Hupfer's answer, which was posted a couple of minutes earlier than mine, provides a more in-depth diagnosis of the nature of the conflict conflict.) Interestingly, the three answers to the query Reference name of description list item in LaTeX do not appear to fix the spacing issue.

Instead of using the enumitem package, you might consider using the enumerate package. It doesn't offer quite as many bells and whistles as the enumitem package does. However, depending on your formatting needs (about which you've revealed exactly zero so far...), the enumerate package may offer all the functionality you really need.

If, however, you simply must use the enumitem package, I suggest you not employ the basic-LaTeX \label-\ref mechanism inside description environments. Instead, use the more general \hypertarget-\hyperlink mechanism of the hyperref package.

\documentclass{article}
\usepackage{enumerate}
\usepackage[colorlinks]{hyperref}

\begin{document}
\begin{description}
\item[\hypertarget{desc:category}{Category}] blablabla
\item[\hypertarget{desc:profile}{Profile}] blabla
(\hyperlink{desc:category}{Category}) blabla
\end{description}
\end{document}

• Thanks, that did the trick. I was using enumitem as you guys said. Lesson learned. Thanks Apr 19, 2017 at 22:24

Apparently the O.P. is using enumitem (hint: style=nextline)

enumitem adds a \hfil in the \descriptionlabel macro, so the label would be Category\hfil, leaving a large space to the right.

The description environment of the standard classes (better: LaTeX core) does not have this is undesireful feature.

The idea is to \let\hfil\relax in the \@currentlabelname macro, which is the name that is stored for \nameref.

\documentclass{article}
\usepackage{enumitem} % Add easy custom list support
\usepackage{hyperref} % Add ref support
%\setlength\parindent{0pt} % Globally set indentation for new paragraphs
\setlist[description]{labelwidth=0pt,leftmargin=30pt,itemindent=\dimexpr-20pt-\labelsep\relax} % Global Setup Description List

\makeatletter % Redefinition of Description List Items source: http://tex.stackexchange.com/a/1248/13552
\let\orgdescriptionlabel\descriptionlabel
\renewcommand*{\descriptionlabel}[1]{%
\let\orglabel\label
\let\label\@gobble
\phantomsection
\protected@edef\@currentlabel{#1}%
\edef\@currentlabelname{\let\hfil\relax #1}%
\let\label\orglabel
\orgdescriptionlabel{#1}%
}
\makeatother

\begin{document}
\begin{description}
\item [Category\label{desc:category}] blablabla
\item [Profile\label{desc:profile}] blabla (\nameref{desc:category}) blabla.
\end{description}

\end{document}


If you look at the .aux file, you see

\newlabel{desc:category}{{}{1}{\enit@align {\enit@format {Category\label {desc:category}}}}{Doc-Start}{}}
\newlabel{desc:profile}{{}{1}{\enit@align {\enit@format {Profile\label {desc:profile}}}}{Doc-Start}{}}


and we want to get rid of \enit@align and \enit@format; this can be done by loading the gettitlestring package with the expand option and disabling the two unwanted commands by making them simply deliver their argument. This redefinition is only temporary, when nameref macros are gathering the title.

\documentclass{article}
\usepackage{enumitem} % Add easy custom list support
\usepackage[expand]{gettitlestring}
\usepackage{hyperref} % Add ref support
\setlist[description]{% Global Setup Description List
labelwidth=0pt,
leftmargin=30pt,
itemindent=\dimexpr-20pt-\labelsep\relax
}

\makeatletter
\GetTitleStringDisableCommands{%
\let\enit@align\@firstofone
\let\enit@format\@firstofone
}
\makeatother

\begin{document}
\begin{description}
\item [Category\label{desc:category}] blablabla
\item [Profile\label{desc:profile}] blabla (\nameref{desc:category}) blabla.
\end{description}

\end{document}


Now the .aux file has

\newlabel{desc:category}{{}{1}{Category}{Doc-Start}{}}
\newlabel{desc:profile}{{}{1}{Profile}{Doc-Start}{}}


and the output is as expected.