# spacing issues with fonts and size

I am switching the font as well as the size in a sentence, and I am also using anyfontsize to give me a few more options to make text look nicer. Here is the code:

One\renewcommand{\familydefault}{\sfdefault}
\normalfont % this is required for the change to take effect
{\fontsize{8}{9.6}\selectfont apple}
\renewcommand{\familydefault}{\rmdefault}
\normalfont among five\renewcommand{\familydefault}{\sfdefault}
\normalfont % this is required for the change to take effect
{\fontsize{8}{9.6}\selectfont oranges}
\renewcommand{\familydefault}{\rmdefault}
\normalfont % this is required for the change to take effect
.


and it looks like this:

as you can see the space between "apple" and "among", "oranges" and "." is not consistent with the others, any idea why?

-

You have number of spurious spaces (see What is the use of percent signs (%) at the end of lines?) that is causing the problem:

\documentclass{article}
\newcommand{\fontchange}[1]{\textsf{\footnotesize #1}}
\begin{document}

One\renewcommand{\familydefault}{\sfdefault}
\normalfont % this is required for the change to take effect
{\fontsize{8}{9.6}\selectfont apple}
\renewcommand{\familydefault}{\rmdefault}% <------ Spurious space
\normalfont among five\renewcommand{\familydefault}{\sfdefault}
\normalfont % this is required for the change to take effect
{\fontsize{8}{9.6}\selectfont oranges}% %  <------ Spurious space
\renewcommand{\familydefault}{\rmdefault}% <------ Spurious space
\normalfont % this is required for the change to take effect
.

One \fontchange{apple} among five \fontchange{oranges}.

\end{document}


The alternative (better) option is to define a macro that does the font changes uniformly. It'll also make your code more readable.

-
There is no reason for redefining \familydefault and issuing \normalfont. – egreg Aug 30 '14 at 9:54

You shouldn't be redefining \familydefault to begin with. Also issuing \normalfont is not needed.

Just issue \sffamily (which implicitly also does \selectfont) in a group:

\documentclass{article}
\usepackage{mathptmx}
\usepackage{helvet}

\begin{document}

One {\fontsize{8}{9.6}\sffamily apple} among five
{\fontsize{8}{9.6}\sffamily oranges}.

\end{document}


This is what you get without the \fontsize declaration and with the handier \textsf command:

\documentclass{article}
\usepackage{mathptmx}
\usepackage{helvet}

\begin{document}

One \textsf{apple} among five \textsf{oranges}.

\end{document}


Oh, the sans serif words are too big! Yes, they are, but there's a simple way to make them smaller without doing complicated manoeuvers: passing the scaled=... option to helvet.

\documentclass{article}
\usepackage{mathptmx}
\usepackage[scaled=.8]{helvet}

\begin{document}

One \textsf{apple} among five \textsf{oranges}.

\end{document}


-

The whole font-scaling thing becomes a non-issue if you can switch to either XeLaTeX or LuaLaTeX:

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{fontspec}
\setmainfont{XITS} % a Times Roman clone
\setsansfont[Scale=MatchLowercase]{Helvetica Neue}
\begin{document}
One \textsf{apple} among five \textsf{oranges}.
\end{document}


In the present case, Scale=MathLowercase seems to be appropriate. For other situations, Scale=MathUppercase may be called for. For very special situations, you can also set Scale=<number> directly; here, <number> should be a positive scalar, generally in the vicinity of 1.

-