Text FormattingDefining a title with \myfont but in bold

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Ranalli13
Posts: 5
Joined: Tue Mar 23, 2021 7:59 pm

Defining a title with \myfont but in bold

Post by Ranalli13 »

Dear Latex Community,

I want to know if someone can help me with a problem of text formatting.

I want to define part of my tittle in bold. The problem is that i used the \myfont to define a different size for the text and if i use \textbf or \bfseries, the \myfont doesn't work.

The output that i want to achieve is: MASTER IN SCIENCE IN
FINANCE

I used the below code to define the first line at 22 and the second at 18.

Code: Select all

\font\myfont=cmr12 at 22pt
       \myfont MASTER OF SCIENCE IN

Code: Select all

\font\myfont=cmr12 at 18pt  
        \myfont FINANCE
What i want now is that the first line be with the 22 size, but in bold.

Can someone help with this?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Defining a title with \myfont but in bold

Post by Bartman »

Do you see a way to enhance your introductory post with a Infominimal working example?
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Defining a title with \myfont but in bold

Post by Ijon Tichy »

Under LaTeX, one should avoid the TeX primitive \font and instead use the lower-level font selection method documented in the fntguide. Computer Modern Roman (cmr) is the default font. Selecting the font size can be done depending either on the base font size:

Code: Select all

\documentclass[10pt]{article}% This is the default of article.
\usepackage{booktabs}
\newcommand*{\thefontsize}{}
\newcommand*{\getfontsize}[1]{%
  #1\strut\csname f@size\endcsname\,pt
}
\newcommand*{\fontsizerow}[1]{\texttt{\string#1} & \getfontsize#1 }
\begin{document}
\begin{tabular}{@{}lr@{}}
\toprule
Font size command & resulting size \\
\midrule
\fontsizerow\tiny\\
\fontsizerow\scriptsize\\
\fontsizerow\footnotesize\\
\fontsizerow\small\\
\fontsizerow\normalsize\\
\fontsizerow\large\\
\fontsizerow\Large\\
\fontsizerow\LARGE\\
\fontsizerow\huge\\
\fontsizerow\Huge\\
\bottomrule
\end{tabular}

And always (not) working: {\fontsize{22pt}{27pt}\selectfont\strut 22\,pt \textbf{bold}}.
\end{document}
or

Code: Select all

\documentclass[11pt]{article}
\usepackage{booktabs}
\newcommand*{\thefontsize}{}
\newcommand*{\getfontsize}[1]{%
  #1\strut\csname f@size\endcsname\,pt
}
\newcommand*{\fontsizerow}[1]{\texttt{\string#1} & \getfontsize#1 }
\begin{document}
\begin{tabular}{@{}lr@{}}
\toprule
Font size command & resulting size \\
\midrule
\fontsizerow\tiny\\
\fontsizerow\scriptsize\\
\fontsizerow\footnotesize\\
\fontsizerow\small\\
\fontsizerow\normalsize\\
\fontsizerow\large\\
\fontsizerow\Large\\
\fontsizerow\LARGE\\
\fontsizerow\huge\\
\fontsizerow\Huge\\
\bottomrule
\end{tabular}

And always (not) working: {\fontsize{22pt}{27pt}\selectfont\strut 22\,pt \textbf{bold}}.
\end{document}
or

Code: Select all

\documentclass[12pt]{article}
\usepackage{booktabs}
\newcommand*{\thefontsize}{}
\newcommand*{\getfontsize}[1]{%
  #1\strut\csname f@size\endcsname\,pt
}
\newcommand*{\fontsizerow}[1]{\texttt{\string#1} & \getfontsize#1 }
\begin{document}
\begin{tabular}{@{}lr@{}}
\toprule
Font size command & resulting size \\
\midrule
\fontsizerow\tiny\\
\fontsizerow\scriptsize\\
\fontsizerow\footnotesize\\
\fontsizerow\small\\
\fontsizerow\normalsize\\
\fontsizerow\large\\
\fontsizerow\Large\\
\fontsizerow\LARGE\\
\fontsizerow\huge\\
\fontsizerow\Huge\\
\bottomrule
\end{tabular}

And always (not) working: {\fontsize{22pt}{27pt}\selectfont\strut 22\,pt \textbf{bold}}.
\end{document}
Why is there the "(not)" in the last sentence? Because of these warnings in the log-file:

Code: Select all

LaTeX Font Warning: Font shape `OT1/cmr/m/n' in size <22> not available
(Font)              size <20.74> substituted on input line 27.

LaTeX Font Warning: Font shape `OT1/cmr/bx/n' in size <22> not available
(Font)              size <20.74> substituted on input line 27.

LaTeX Font Warning: Size substitutions with differences
(Font)              up to 1.26pt have occurred.
The reason for these warning is: Computer Modern Roman has discrete font design sizes. So usually not all sizes are available in LaTeX. However there are two methods to solve this:
  1. Add \RequirePackage{fix-cm} before \documentclass.
  2. Use a scalable font, e.g., adding \usepackage{lmodern} somewhere between \documentclass[…]{article} and \begin{document}
So either:

Code: Select all

\RequirePackage{fix-cm}
\documentclass[10pt]{article}% This is the default of article.
\usepackage{booktabs}
\newcommand*{\thefontsize}{}
\newcommand*{\getfontsize}[1]{%
  #1\xdef\thefontsize{\csname f@size\endcsname}%
  \strut\thefontsize\,pt
}
\newcommand*{\fontsizerow}[1]{\texttt{\string#1} & \getfontsize#1 }
\begin{document}
\begin{tabular}{@{}lr@{}}
\toprule
Font size command & resulting size \\
\midrule
\fontsizerow\tiny\\
\fontsizerow\scriptsize\\
\fontsizerow\footnotesize\\
\fontsizerow\small\\
\fontsizerow\normalsize\\
\fontsizerow\large\\
\fontsizerow\Large\\
\fontsizerow\LARGE\\
\fontsizerow\huge\\
\fontsizerow\Huge\\
\bottomrule
\end{tabular}

And always working: {\fontsize{22pt}{27pt}\selectfont\strut 22\,pt \textbf{bold}}.
\end{document}
or

Code: Select all

\documentclass[10pt]{article}% This is the default of article.
\usepackage{lmodern}
\usepackage{booktabs}
\newcommand*{\thefontsize}{}
\newcommand*{\getfontsize}[1]{%
  #1\xdef\thefontsize{\csname f@size\endcsname}%
  \strut\thefontsize\,pt
}
\newcommand*{\fontsizerow}[1]{\texttt{\string#1} & \getfontsize#1 }
\begin{document}
\begin{tabular}{@{}lr@{}}
\toprule
Font size command & resulting size \\
\midrule
\fontsizerow\tiny\\
\fontsizerow\scriptsize\\
\fontsizerow\footnotesize\\
\fontsizerow\small\\
\fontsizerow\normalsize\\
\fontsizerow\large\\
\fontsizerow\Large\\
\fontsizerow\LARGE\\
\fontsizerow\huge\\
\fontsizerow\Huge\\
\bottomrule
\end{tabular}

And always working: {\fontsize{22pt}{27pt}\selectfont\strut 22\,pt \textbf{bold}}.
\end{document}
would do it.

Note, if you are using a different base font, you may have so use \fontfamily to select Computer Modern Roman.

See the fntguide and a proper introduction to LaTeX for more information about font selection commands with LaTeX.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Ranalli13
Posts: 5
Joined: Tue Mar 23, 2021 7:59 pm

Defining a title with \myfont but in bold

Post by Ranalli13 »

Thanks for the information. I will work then with these sizes. All the best
Post Reply