gpt4 book ai didi

latex - 设置一个介于 small 和 normalsize 之间的大小

转载 作者:行者123 更新时间:2023-12-03 22:13:19 25 4
gpt4 key购买 nike

我正在使用列表包,在列表中设置字体大小的命令是:

\lstset{basicstyle = \small}

我想修改它以使用介于\small 和\normalsize 之间的字体大小。像这样的东西不起作用:
\lstset{basicstyle = 0.5\small+0.5\normalsize}

有什么方法可以根据需要设置字体大小吗?

最佳答案

这取决于您的文档类设置。例如,\small10pt文档类选项是 9pt\normalsize10pt (当然,因为类选项)。见 What point (pt) font size are \Large etc.?其他尺寸基于 \documentclass .在此基础上,设置您的 basicstyle9.5pt (带有适当的中间基线跳过)手动通过 \fontsize{9.5}{11.5}\selectfont ,或通过 \smalltonormalsize 使用以下自动计算作为字体开关:

enter image description here

\documentclass{article}

\usepackage{listings,xfp}
\usepackage{anyfontsize}

\makeatletter
{\small % Capture font definitions of \small
\xdef\f@size@small{\f@size}
\xdef\f@baselineskip@small{\f@baselineskip}
\normalsize % Capture font definitions for \normalsize
\xdef\f@size@normalsize{\f@size}
\xdef\f@baselineskip@normalsize{\f@baselineskip}
}
% Define new \smalltonormalsize font size
\newcommand{\smalltonormalsize}{%
\fontsize
{\fpeval{(\f@size@small+\f@size@normalsize)/2}}
{\fpeval{(\f@baselineskip@small+\f@baselineskip@normalsize)/2}}%
\selectfont
}
\makeatother

\begin{document}

\begin{lstlisting}[basicstyle = \ttfamily\small]
Hello world A
\end{lstlisting}

\begin{lstlisting}[basicstyle = \ttfamily\smalltonormalsize]
Hello world B
\end{lstlisting}

\begin{lstlisting}[basicstyle = \ttfamily\normalsize]
Hello world C
\end{lstlisting}

\end{document}

关于latex - 设置一个介于 small 和 normalsize 之间的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52745707/

25 4 0