Text FormattingFontspec and fontsize command

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
theo moore
Posts: 72
Joined: Thu Jan 15, 2009 3:16 pm

Fontspec and fontsize command

Post by theo moore »

For some reason, I can't seem to adjust the leading (interline space) when using \fontsize with \fontspec. Here, \fontsize{10}{12} should give me a font with 10pt size and 12pt leading. But when enclosed in curly braces, it does not work. That is,

Code: Select all

\fontsize{18}{50}
\fontspec{Adobe Caslon Pro}
Text goes here
is not the same as

Code: Select all

{
\fontsize{18}{50}
\fontspec{Adobe Caslon Pro}
Text goes here
}

Here is a minimum example:

Code: Select all

\documentclass[11pt,a4paper]{memoir}

\usepackage{leading}
\usepackage{fontspec} 
\usepackage{xunicode} 
\usepackage{xltxtra}

\defaultfontfeatures{Mapping=tex-text} %converts quotes, dashes, ... to unicode
\setromanfont [Ligatures={Common},Numbers={OldStyle}]{Adobe Caslon Pro}

\pagestyle{empty}

\begin{document}
{
\fontsize{18}{20}
\fontspec{Adobe Caslon Pro}
\noindent This is a line with size 18pt and \\
leading of 20 pt
}

\mbox{}\par
{
\fontsize{18}{30}
\fontspec{Adobe Caslon Pro}
\noindent This is a line with size 18pt and \\
leading of 30 pt. Why is there no difference?
}

\mbox{}\par
{
\fontsize{28}{30}
\fontspec{Adobe Caslon Pro}
\noindent Changing the font size works \\
But the leading has no change
}


\mbox{}\par
\fontsize{18}{50}
\fontspec{Adobe Caslon Pro}
\noindent It only works \\
If you remove the curly braces. Why???

\end{document}
Last edited by theo moore on Fri Jun 11, 2010 11:36 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Fontspec and fontsize command

Post by frabjous »

Someone with more TeX knowledge than I may be able to explain it better, but I think the interline space (\baselineskip) attribute it something that is applied to the paragraph as a whole, when it is "shipped out" so to speak, and hence if the \fontsize{..}{..} command is used inside braces that don't include the end of the paragraph, that part of it has no effect on the paragraph.

You should be able to remedy this by including the end of the paragraph as part of what's inside the braces, which is done either by the \par command, or by leaving a blank line.

Try this out, for example:

Code: Select all

\documentclass[11pt,a4paper]{memoir}

\usepackage{leading}
\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}

\defaultfontfeatures{Mapping=tex-text} %converts quotes, dashes, ... to unicode
\setromanfont[Ligatures={Common},Numbers={OldStyle}]{Adobe Caslon Pro}

\pagestyle{empty}

\begin{document}

\noindent Here is some text \\ at the beginning.

{\fontsize{18}{50}
\fontspec{Adobe Caslon Pro}
\noindent This should look the same \\
as what is below.

}% Notice that there's a blank line at the end of the part in braces

\bigskip

\noindent Here is some \\ intermediate text. 

\fontsize{18}{50}
\fontspec{Adobe Caslon Pro}
\noindent This should look the same \\
as the above.
\end{document}
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Fontspec and fontsize command

Post by localghost »

Usually it requires activation of the chosen font attribute.

Code: Select all

\fontsize{20}{24}\selectfont

Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
theo moore
Posts: 72
Joined: Thu Jan 15, 2009 3:16 pm

Fontspec and fontsize command

Post by theo moore »

localghost wrote:Usually it requires activation of the chosen font attribute.

Code: Select all

\fontsize{20}{24}\selectfont

Thorsten
Thorsten,

I did do this earlier, but it seems afflicted with the same problem [that frabjous addresses]. That is,

Code: Select all

\fontsize{20}{50}
\selectfont
This line does \\
have 50pt leading
and

Code: Select all

{
\fontsize{20}{50}
\selectfont
But this line does \\
not have 50pt leading
}
It's a bit of a strange problem, but perhaps the explanation frabjous will suffice...?
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Re: Fontspec and fontsize command

Post by frabjous »

I think that Fontspec's \fontspec command does what \selectfont does (--in fact, that may be part of its definition, I'm too lazy to look--) so that's not the issue here.

Do let us know if my suggestions above are of any help. I've never really had the need to fiddle much with fontsize/leading size when using fontspec.
theo moore
Posts: 72
Joined: Thu Jan 15, 2009 3:16 pm

Fontspec and fontsize command

Post by theo moore »

frabjous wrote:I think that Fontspec's \fontspec command does what \selectfont does (--in fact, that may be part of its definition, I'm too lazy to look--) so that's not the issue here.

Do let us know if my suggestions above are of any help. I've never really had the need to fiddle much with fontsize/leading size when using fontspec.
Dear frabjous,

Thanks for your help. I think you're right and that I'll simply have to make sure to always end any entries [within curly braces] with \par

Since I already have you on the line, then a more general question is: how do I have control over spacing in my document, which is a long monograph and not only a few pages for which I can do everything manually?

One idea is to use the \linespread command (or the leading) package, which will set a single multiplier for the leading for all the fonts (\normalfont, \small, \huge, etc.). The problem with this is that I need different leadings for figure captions and footnotes, and so on.

In a sense, this is slightly remedied by the setspace package, but I would still like to specify different leadings for certain areas (as a silly example, suppose I wanted my main text to be \fontsize{10}{20} but my captions to be \fontsize{10}{15}).

I think the easiest way is to simply redefine all the sizes:

Code: Select all

\renewcommand{\normalsize}{\fontsize{11}{13}\selectfont}
\renewcommand{\small}{\fontsize{10}{15}\selectfont}
\renewcommand{\huge}{\fontsize{20}{30}\selectfont}
...and so on. In actuality, I only use maybe three of the total twelve size commands. This should take care of caption/footnote packages that use \small or \footnotesized. Afterwards, most things can be handled on a case-by-case basis.

Would this be the best idea? Thoughts?
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Fontspec and fontsize command

Post by frabjous »

I've usually used the setspace package to handle spacing issues, but I've never really tried to do anything fancy with footnotes or captions. Perhaps one of the packages devoted to those (bigfoot, caption, etc.), would have solutions? Someone who knows more than I may be able to answer.
theo moore
Posts: 72
Joined: Thu Jan 15, 2009 3:16 pm

Re: Fontspec and fontsize command

Post by theo moore »

Okay, I think I'm pretty happy with the solution(s) proposed. We'll mark this one as closed. :)
Post Reply