同一张表中的两种不同字体

同一张表中的两种不同字体

我的目标是在左侧使用 PCR 字体,在右侧使用普通字体(例如 ssfamily 字体)。不使用 XeTeX 可以实现吗?如果您问自己为什么需要这样做,我想在左侧(命令/功能)和右侧添加描述,而不是总是使用\texttt{}

\documentclass[a4paper]{article}
\usepackage{tabularx} % in the preamble
\usepackage[a4paper, top=3cm, bottom=3cm, left=3cm, right=3cm, marginparwidth=2cm, headsep=1.2cm]{geometry} % layout

\begin{document}
% ....
\begin{table}[ht!]
 \fontfamily{pcr}\selectfont
\begin{tabularx}{\textwidth}{X X}
  \textbf{Function} & \textbf{Meaning} \\
\hline
asdf & ATFD is more than a few\\
Class that is large and complex & WMC is high\\
Class that has a lot of methods that only operate on a proper subset of the instance variable set & TCC is low\\
\end{tabularx}
\end{table}
\end{document}

答案1

这完美无缺

\documentclass[a4paper]{article}
\usepackage{tabularx} % in the preamble
\usepackage[a4paper, top=3cm, bottom=3cm, left=3cm, right=3cm, marginparwidth=2cm, headsep=1.2cm]{geometry} % layout

\begin{document}
% ....
\begin{table}[ht!]

\begin{tabularx}{\textwidth}{>{\ttfamily}X X}
  \textbf{Function} & \textbf{Meaning} \\
\hline
asdf & ATFD is more than a few\\
Class that is large and complex & WMC is high\\
Class that has a lot of methods that only operate on a proper subset of the instance variable set & TCC is low\\
\end{tabularx}
\end{table}
\end{document}

相关内容