4

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:

enter image description here

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

0

3 Answers 3

3

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

enter image description here

\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.

1
  • There is no reason for redefining \familydefault and issuing \normalfont.
    – egreg
    Aug 30, 2014 at 9:54
3

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

enter image description here

% !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.

2

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}

enter image description here

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}

enter image description here

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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .