最有价值球员:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{lmodern}
\usepackage{color}
\usepackage{tcolorbox}
\usepackage{float} % Better figure and table placements
\usepackage{tabularx}
\usepackage{tabularray}
\usepackage{multirow}
\begin{document}
\providecolor{keywords}{HTML}{aa5099}
{\renewcommand{\arraystretch}{1.3}%
\begin{table}[H]
\centering\sffamily\tabcolsep=2.5ex\relax
\footnotesize
\begin{tabular}{>{\color{keywords}}l>{\color{keywords}}l>{\color{keywords}}l>{\color{keywords}}l>{\color{keywords}}l}
cond & in & not & boolean & break\\
const & continue & decimal & default & define \\
do & intersect & union & loop & infinity \\
lambda & sum & division & pi & tau \\
sin & cos & tan & int & float \\
rational & real & complex&&
\end{tabular}\par
\end{table}
}
\end{document}
输出:
我想要一个像字体一样的代码,就像使用\texttt{}
或时一样\verb
。如何在一个地方设置它并使用相同的字体影响所有值?
答案1
如果表格内的所有内容都应该以相同的方式处理,则设置字体(和颜色)更改外部这tabular
:
\documentclass{article}
\usepackage{xcolor}
\begin{document}
\providecolor{keywords}{HTML}{aa5099}
\begin{center}
\setlength{\tabcolsep}{2.5ex}%
\renewcommand{\arraystretch}{1.3}%
\footnotesize\ttfamily
\color{keywords}%
\begin{tabular}{ *{5}{l} }
cond & in & not & boolean & break \\
const & continue & decimal & default & define \\
do & intersect & union & loop & infinity \\
lambda & sum & division & pi & tau \\
sin & cos & tan & int & float \\
rational & real & complex & &
\end{tabular}
\end{center}
\end{document}
您不必tabular
在里面设置table
。它也可以独立存在。
答案2
使用tabularray
包装很简单:
\documentclass{article}
\usepackage{lmodern}
\usepackage{xcolor}
\providecolor{keywords}{HTML}{aa5099}
\usepackage{tabularray}
\begin{document}
\begin{table}[!ht]
\begin{tblr}{colspec={@{} *{5}{X[l, font=\ttfamily, fg=keywords]} @{}}}
cond & in & not & boolean & break \\
const & continue & decimal & default & define \\
do & intersect & union & loop & infinity \\
lambda & sum & division & pi & tau \\
sin & cos & tan & int & float \\
rational & real & complex & &
\end{tblr}
\end{table}
\end{document}