保持電腦現代化為粗體

保持電腦現代化為粗體

我想使用 Gentium 作為我的主字體,這是透過指令 \usepackage{Gentium} 完成的。但我希望「Computer Modern」成為我的粗體字體。知道如何做嗎?

答案1

沒有Gentium包裹,但是gentium;在套件名稱中使用大寫可以在不區分大小寫的檔案系統 (Windows) 中運作,但會限製檔案的可移植性,因為\usepackage{Gentium}在 GNU/Linux 或 Mac OS X 系統上不起作用。

一個簡單的解決方案是透過修補\bfseries\mdseries檢查當前字體系列,如果它是預設字體系列 ( gentium),則切換到 CM,對於\bfseries;相反,如果字體系列是 CM,則切換到gentium.

其他字體系列不受影響,如範例所示。

然而,該範例還表明 Computer Moder Roman Bold 在視覺上與 Gentium 不相容,因此我強烈建議您不要這樣做。 Adventor 和 Cursor 在這裡僅作為範例使用,我並不聲稱它們要與 Gentium 一起使用。

作為一般印刷規則,普通文件應僅使用一種襯線字體系列。

\documentclass{article}
\usepackage{gentium}
\usepackage{tgadventor}
\usepackage{tgcursor}
\usepackage{xpatch,pdftexcmds}

\xpatchcmd{\bfseries}
  {\selectfont}
  {\checkfamily{\familydefault}{cmr}\selectfont}
  {}{}
\xpatchcmd{\mdseries}
  {\selectfont}
  {\checkfamily{cmr}{\familydefault}\selectfont}
  {}{}

\makeatletter
\newcommand{\checkfamily}[2]{%
  \ifnum\pdf@strcmp{\f@family}{#1}=\z@
    \fontfamily{#2}%
  \fi
}
\makeatother

\begin{document}
Some text in Gentium and \textbf{some in CM {\mdseries (this is Gentium)} and back to CM}

\sffamily
Some text in Adventor and \textbf{some in bf {\mdseries (this is md)} and back to bf}

\ttfamily
Some text in Cursor and \textbf{some in bf {\mdseries (this is md)} and back to bf}

\end{document}

在此輸入影像描述

放大視圖更好地顯示字體衝突

在此輸入影像描述

更長且可能更可靠的解決方案涉及修改.fdGentium 的文件。

如果你使用 XeLaTeX 或 LuaLaTeX,那麼你可以更容易得到這個:

\usepackage{fontspec}

\setmainfont{Gentium}[
  BoldFont={Latin Modern Roman 10 Bold}
]
\setsansfont{TeX Gyre Adventor}
\setmonofont{TeX Gyre Cursor}

應該需要對尺寸進行更多調整。

相關內容