问题

问题

我想创建一个默认字体大小列表。该列表不应仅包含磅值,还应包含用于实现这些大小的实际 LaTeX 命令。

问题

示例中各行上的基线并不相等。

例子

\documentclass{article}
\usepackage{fontspec}
\usepackage[margin=3cm]{geometry}
\makeatletter
\newcommand\thefontsize[1]{{#1 The current font size is: \f@size pt\par}}
\makeatother
\begin{document}
\section{Font Sizes}
\thefontsize\tiny \hfill tiny\\
\thefontsize\scriptsize \hfill scriptsize\\
\thefontsize\footnotesize \hfill footnotesize\\
\thefontsize\small \hfill small\\
\thefontsize\normalsize \hfill normalsize\\
\thefontsize\large \hfill large\\
\thefontsize\Large \hfill Large\\
\thefontsize\LARGE \hfill LARGE\\
\thefontsize\huge \hfill huge\\
\thefontsize\Huge \hfill Huge\\
\end{document}

答案1

这取决于您所说的“示例中各行上的基线不相等”是什么意思:如果您没有将基线设置为等于最大尺寸所需的基线,则它们就不能相等。

如果您希望行距(行与行之间的距离)在所有情况下都相同,则需要禁用行间跳过机制并设置\lineskip为您希望的量。

请注意,使用当前执行\par的值;对于这两种实现,只需在您排版样本行的组之外使用即可。\baselineskip\par\par

\documentclass{article}
\usepackage[margin=3cm]{geometry}

\makeatletter
\newcommand\thefontsize[1]{%
  {#1 The current font size is: \f@size pt \hfill\texttt{\string#1}}\par}
\makeatother

\begin{document}
\section{Font Sizes}

\begingroup\Huge\setlength{\parindent}{0pt}
\thefontsize\tiny
\thefontsize\scriptsize
\thefontsize\footnotesize
\thefontsize\small
\thefontsize\normalsize
\thefontsize\large
\thefontsize\Large
\thefontsize\LARGE
\thefontsize\huge
\thefontsize\Huge
\endgroup

\bigskip
\begingroup\offinterlineskip\setlength{\lineskip}{4pt}
\thefontsize\tiny
\thefontsize\scriptsize
\thefontsize\footnotesize
\thefontsize\small
\thefontsize\normalsize
\thefontsize\large
\thefontsize\Large
\thefontsize\LARGE
\thefontsize\huge
\thefontsize\Huge
\endgroup


\end{document}

在此处输入图片描述

答案2

好吧,我发现了我自己的问题。只需\par从自定义命令中删除\thefontsize。根据我的理解,\par结束给定行的基线。

\documentclass{article}
\usepackage{fontspec}
\usepackage[margin=3cm]{geometry}
\makeatletter
\newcommand\thefontsize[1]{{#1 The current font size is: \f@size pt}}
\makeatother
\begin{document}
\section{Font Sizes}
\thefontsize\tiny \hfill tiny\\
\thefontsize\scriptsize \hfill scriptsize\\
\thefontsize\footnotesize \hfill footnotesize\\
\thefontsize\small \hfill small\\
\thefontsize\normalsize \hfill normalsize\\
\thefontsize\large \hfill large\\
\thefontsize\Large \hfill Large\\
\thefontsize\LARGE \hfill LARGE\\
\thefontsize\huge \hfill huge\\
\thefontsize\Huge \hfill Huge\\
\end{document}

为了实现我的目标,我尝试在命令中添加文字信息,以便可以打印输入变量(例如\Huge)。最终我得到了一些意想不到的结果。

添加listings

将命令更改为:

\makeatletter
\newcommand\thefontsize[1]{{#1 The current font size is: \f@size pt\hfill\lstinline|test|\par}}
\makeatother

在此处输入图片描述

相关内容