在@Johan_E 的回答中在 LaTeX 中應該使用哪一種測量單位?,有一些有用的圖表顯示 1em 的大小(以磅為單位)、an 的寬度M
、1ex 和 的高度x
。我怎麼才能製作這樣的圖表?最有用的是如何產生第一行來說明測量命令和/或另一行(例如 bf、it)來說明如何完成字體選擇的範例。 (我知道如何得到一個 bf,it M
,但是我如何得到一個 bf,it 呢1em
?)
我總是嘗試縮放 zlmtt 以匹配我的字體,放大 pdf 檢視器螢幕並目視它。進行實際測量將使這種縮放變得更加容易。
採用下面評論中@jfbu 的建議,我從 xintools 循環中提取了以下內容,這似乎有效。
\documentclass{article}
\usepackage[T1]{fontenc}
\newcommand\oneem{}
\newcommand\oneex{}
\newcommand\Mwidth{}
\newcommand\xheight{}
\newcommand\xwidth{}
\newcommand\xdepth{}
\begin{document}
\edef\oneem{\the\dimexpr 1em\relax}%
\edef\oneex{\the\dimexpr 1ex\relax}%
\setbox0\hbox{M}%
\edef\Mwidth{\the\wd0}%
\setbox0\hbox{x}%
\edef\xheight{\the\ht0}%
\edef\xwidth{\the\wd0}%
\edef\xdepth{\the\dp0}%
%
\begin{tabular}{lllllll}
font & 1em & M-width & 1ex & x-height & x-width & x-depth \\
rm & \oneem & \Mwidth & \oneex & \xheight & \xwidth & \xdepth
\end{tabular}
\end{document}
答案1
幹得好:
\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[margin=1cm]{geometry}
\usepackage{xinttools}
\newcommand\WithFont [4]{%
\csname text#1\endcsname {%
\csname text#3\endcsname {%
\csname text#2\endcsname {#4}}}}
\begin{document}
\begin{table}
\centering
\Large\textbf{Computer Modern fonts (pdf\LaTeX) [10pt]}\\
\small
Selected using \detokenize{\textA{\textB{\textC{(some text)}}}},\\
with A in \detokenize{{rm, sf, tt}}; B in \detokenize{{md, bf}}; C in
\detokenize{{up, it, sl, sc}}\\
\begin{tabular}{*{9}{l}}
\bf Font&\bf 1em&&\bf M-width&\bf 1ex&&\bf x-height&\bf x-width&\bf x-depth\\
\hline
\xintForpair #1#2 in {(Roman,rm), (Sans,sf), (Typewriter,tt)} \do
{%
\xintFor #3 in {up, it, sl, sc}\do
{%
\xintFor #4 in {md, bf}\do
{%
\WithFont {#2}{#3}{#4}{#1, #3, #4\normalsize
\xdef\oneem{\the\dimexpr 1em\relax}%
\xdef\oneex{\the\dimexpr 1ex\relax}%
\setbox0\hbox{M}\xdef\Mwidth{\the\wd0}%
\setbox0\hbox{x}\xdef\xheight{\the\ht0}%
\xdef\xwidth{\the\wd0}%
\xdef\xdepth{\the\dp0}}%
&\oneem&\WithFont{#2}{#3}{#4}{\normalsize\strut M}&\Mwidth
&\oneex&\WithFont{#2}{#3}{#4}{\normalsize x}&\xheight&\xwidth&\xdepth
\\
}%
}\hline
}\hline
\end{tabular}
\end{table}
\end{document}
(\normalsize
在編輯中添加,因為所有表格都是在\small
製度下較早生成的,包括尺寸的計算)。
請注意,在上表中,進行了許多字體替換:
LaTeX Font Warning: Font shape `T1/cmss/m/sc' in size <9> not available
(Font) Font shape `T1/cmr/m/sc' tried instead on input line 55.
LaTeX Font Warning: Font shape `T1/cmss/m/sc' in size <10> not available
(Font) Font shape `T1/cmr/m/sc' tried instead on input line 55.
LaTeX Font Warning: Font shape `T1/cmss/bx/sc' undefined
(Font) using `T1/cmss/bx/n' instead on input line 55.
LaTeX Font Info: Font shape `T1/cmtt/bx/n' in size <9> not available
(Font) Font shape `T1/cmtt/m/n' tried instead on input line 55.
LaTeX Font Info: Font shape `T1/cmtt/bx/n' in size <10> not available
(Font) Font shape `T1/cmtt/m/n' tried instead on input line 55.
LaTeX Font Info: Font shape `T1/cmtt/bx/it' in size <9> not available
(Font) Font shape `T1/cmtt/m/it' tried instead on input line 55.
LaTeX Font Info: Font shape `T1/cmtt/bx/it' in size <10> not available
(Font) Font shape `T1/cmtt/m/it' tried instead on input line 55.
LaTeX Font Warning: Font shape `T1/cmtt/bx/sl' undefined
(Font) using `T1/cmtt/bx/n' instead on input line 55.
LaTeX Font Info: Font shape `T1/cmtt/bx/sl' in size <10> not available
(Font) Font shape `T1/cmtt/m/n' tried instead on input line 55.
LaTeX Font Info: Font shape `T1/cmtt/bx/sl' in size <9> not available
(Font) Font shape `T1/cmtt/m/n' tried instead on input line 55.
LaTeX Font Warning: Font shape `T1/cmtt/bx/sc' undefined
(Font) using `T1/cmtt/bx/n' instead on input line 55.
LaTeX Font Info: Font shape `T1/cmtt/bx/sc' in size <10> not available
(Font) Font shape `T1/cmtt/m/n' tried instead on input line 55.
LaTeX Font Info: Font shape `T1/cmtt/bx/sc' in size <9> not available
(Font) Font shape `T1/cmtt/m/n' tried instead on input line 55.
例如,我考慮過在整行上畫一條刪除線,但自動執行此操作會很複雜。由於這不是OP的主要焦點,我就保持原樣。
為了自動確定,無恥地將egreg的答案複製到另一種語法。請注意,xinttools
上面使用的包與下面使用的包是分開的xintfrac
。
\documentclass[border=4pt]{standalone}
\usepackage{zlmtt}
\usepackage{xintfrac}
\makeatletter
\newcommand{\scalezlmtt}[2][1]{%
{\setbox0\hbox{\normalfont #2}%
\setbox2\hbox{\fontfamily{lmtt}\selectfont #2}%
\xdef\zlmtt@scale {\xintPFloat {\xintMul{#1}{\ht0/\ht2}}}%
\typeout{zlmtt scaling factor: \zlmtt@scale}%
}%
}%
\makeatother
\AtBeginDocument{\scalezlmtt[.9]{a}}
\begin{document}
TT font scaled to 90\% lowercase: A\texttt{A}a\texttt{a}
\end{document}
你會在日誌中發現:
zlmtt scaling factor: 0.9143980556305698
這與 l3fp 的計算的最後一位數字不同,但這在印刷上沒有那麼相關...
(例如,如果您想要更多--不相關的--數字,請嘗試一下\xintPFloat [32]...
,好吧,我做到了:
zlmtt scaling factor: 0.91439805563056980826357007831488
我真的需要一個比例因子來0.1
隱藏我不相關的玩具)
答案2
我可以提供一個巨集來盡可能自動地確定比例因子:
\documentclass{article}
\usepackage{zlmtt}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\scalezlmtt}{O{1}m}
{
\hbox_set:Nn \l_tmpa_box { \normalfont #2 }
\hbox_set:Nn \l_tmpb_box { \fontfamily{lmtt}\selectfont #2 }
\tl_set:cx { zlmtt@scale }
{
\fp_eval:n
{
#1 *
\dim_to_fp:n { \box_ht:N \l_tmpa_box } /
\dim_to_fp:n { \box_ht:N \l_tmpb_box }
}
}
\typeout{ zlmtt~scaling:~\tl_use:c { zlmtt@scale } }
}
\ExplSyntaxOff
\AtBeginDocument{\scalezlmtt{A}}
\begin{document}
TT font scaled to uppercase: A\texttt{A}a\texttt{a}
\end{document}
如果我將呼叫更改\scalezlmtt{a}
為
\AtBeginDocument{\scalezlmtt{a}}
\begin{document}
TT font scaled to lowercase: A\texttt{A}a\texttt{a}
\end{document}
我明白了
還有一個“修正係數”
\AtBeginDocument{\scalezlmtt[.9]{a}}
\begin{document}
TT font scaled to 90\% lowercase: A\texttt{A}a\texttt{a}
\end{document}
這應該足夠靈活,以避免在表中查找或目測。通過完成這項工作\AtBeginDocument
,呼叫\normalfont
將是正確的。只需在該指令之前載入其他字型包即可,因為其中一些字型包也在開始文件中執行操作。
技巧是用於lmtt
測量,因此這還不會觸發<encoding>zlmtt.fd
.
在日誌檔案中你會看到類似的內容
zlmtt scaling: 0.9143980556305699
(這是最後一個範例使用的值),一旦您確定它適合您,您可能希望對其進行四捨五入並在套件選項中使用。