# Problems with tilde (~) and line breaking

I'm trying to avoid a line break between the word "Table" and the number reference for that table. Following the advice of another Q&A, I went through my whole document and replaced all spaces with tildes between \ref and the Table/Figure text, e.g.: Table~\ref{table:data-from-phone}. However, the line break still occurs:

I can't figure out if this is a bug or whether I am still doing something incorrect. I am using MiKTeX 2.9 and the TexMaker editor. Here is a snippet of code, in case that is helpful:

A user, Mary, has painstakingly collected the following set of data and labelled
whether she was walking, running, or standing still. The data are shown in
Table~\ref{table:data-from-phone} below.


Per comments, here are two files needed to compile an example document where I am having this issue (I tried to make these as small as possible):

%!TeX encoding = ISO-8859-1
\documentclass[12pt,a4paper,english
]{tutthesis2}

\begin{document}
A user, Mary, has painstakingly collected the following set of data and labelled whether she was walking, running, or standing still. The data are shown in Table~\ref{table:data-from-phone} below, consisting of two dimensions of input data and the labelled output.

\begin{table}
\begin{tabular}{lcc}
\hline\noalign{\smallskip}
2.56 & 2 & walking\\
\end{tabular}
\caption{The caption of the table}\label{table:data-from-phone}
\end{table}

\end{document}


and the tutthesis2.cls file:

\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{tutthesis2}
[2014/07/28 v0.5 Extension to basic LaTeX document class 'report']

% Load the basic template 'report.cls'.

\usepackage[font=small,it, labelsep=space]{caption} % Figure caption text font and size,  *
\usepackage{hyperref}       % pdf links to e.g. figures and citations

\setlength\textwidth{15cm}  % 15*24cm text area leaves 6cm horiz margins and 5.7cm vertical
\setlength\textheight{24cm} %

\renewcommand \thetable{
\ifnum \c@chapter>\z@ \chapfigname.\fi \@arabic\c@table}
\captionsetup[table]{labelfont={bf,it},textfont={it}}

%% End of file tutthesis2.cls'.

• This shouldn't happen and it possibly depends on things you're not showing. Can you try producing a compilable example? In my test the ~ works as expected. Feb 9 '15 at 10:29
• Sure. Is it better to post the example here, or post to pastebin or something like that? Thanks. Feb 9 '15 at 10:39
• Better here, try making it as small as possible. Feb 9 '15 at 10:40

Your class has too many whitespaces in the redefinition. If you remove them it works as expected:

\renewcommand\thetable{\ifnum\c@chapter>\z@\chapfigname.\fi\@arabic\c@table}


Even if you typeset it with a protected space, it still inserted a normal space where it could break the line.

I have removed all the other whitespaces (personal preference), but you really only need to remove or escape the whitespace (in this case a linebreak) after the \thetable{. You can either remove the linebreak and the following spaces, or you can escape the linebreak with a %, so it doesn't "count" as whitespace anymore.

• a % after the first brace of the definition would be sufficient. there's no advantage to removing the space after the \z@, \ifnum or \fi. spaces after control sequences are ignored; they only serve to mark the ends of the control sequences, after which they are removed from consideration. Feb 9 '15 at 12:57
• Yes you are of course right. I will add that. Feb 9 '15 at 12:58
• Many thanks! Your solution worked. Also, egreg's guidance to post the full compilable code helped me to narrow down the problem. The original class file was many nearly 500 lines, but it was worth the effort, I think, to isolate the problem. I will try this approach the next time ;-) Feb 9 '15 at 14:12

You may try following commands

\pretolerance=9999
\hyphenpenalty=9999
`

before the \begin{document}. You can adjust the values as per your requirement.