如何設定隨字體重新縮放的距離

如何設定隨字體重新縮放的距離

我正在嘗試設定一個相對於字體大小的距離。問題在於距離在文件中重複使用多次,可能在具有不同字體大小的環境中。在每種情況下,距離都應自動重新縮放以保持其與字體大小的比例。不幸的是,僅僅在em或中指定距離是ex行不通的,因為距離是以當前字體的大小em或大小儲存的。ex當字體改變時,距離不會相應更新。

有沒有解決的辦法?理想情況下,該解決方案應該在 LaTeX 和 PlainTeX 下都能運作。

下面是一個 M(n)WE,它顯示了目前的不良行為。

\documentclass[12pt]{article}

\newskip\test
\test = 1em

\begin{document}

In each row, the lines should be the same length.

\rule{0.4pt}{1em} \rule{0.4pt}{\test}

{\tiny\rule{0.4pt}{1em} \rule{0.4pt}{\test}}

{\Huge\rule{0.4pt}{1em} \rule{0.4pt}{\test}}

\end{document}

答案1

將距離定義為宏,而不是長度暫存器:

\documentclass[12pt]{article}

\newcommand{\test}{1em}

\begin{document}

In each row, the lines should be the same length.

\rule{0.4pt}{1em} \rule{0.4pt}{\test}

{\tiny\rule{0.4pt}{1em} \rule{0.4pt}{\test}}

{\Huge\rule{0.4pt}{1em} \rule{0.4pt}{\test}}

\end{document}

在此輸入影像描述

答案2

您可以為規則定義一個新命令,以便在每次呼叫該命令時重設規則長度。因為要求使用普通相容的解決方案\newskip,但我在其下面添加了註解掉的 LaTeX 版本。

\documentclass[12pt]{article}

\newskip\ruleheight

\def\myrule{%
    \ruleheight = 1em
    \rule{0.4pt}{\ruleheight}%
}

% LaTeX version
%\newlength{\ruleheight}
%\newcommand{\myrule}{%
%    \setlength{\ruleheight}{1em}
%    \rule{0.4pt}{\ruleheight}%
%    

\begin{document}

In each row, the lines should be the same length.

\rule{0.4pt}{1em} \myrule

\tiny \rule{0.4pt}{1em} \myrule

\Huge \rule{0.4pt}{1em} \myrule

\end{document}

底部三行以不同大小顯示新指令的輸出。

在此輸入影像描述

相關內容