我正在嘗試建立一個表格,其中一列中的所有內容均採用打字機字體。換句話說,它應該像這樣執行:
\begin{tabular} {| l | p{5cm} |}
\hline
\multicolumn{2}{|l|}{Sample Table} \\ \hline
\texttt{left a} & right a \\ \hline
\texttt{left b} & right b \\ \hline
\texttt{left c} & right c \\ \hline
\end{tabular}
但是,我想避免\texttt
在每一行上鍵入。有沒有辦法做到這一點?
答案1
您可以使用array
封裝及其先進的色譜管規格。語法是
>{before-code} column-type <{after-code}
wherebefore-code
和after-code
get 在相關列的每個單元格的開頭和結尾(分別)執行。在這裡,你應該使用
>{\ttfamily}l
這會產生一個左對齊的列,其單元格以打字機字體排版。
\documentclass{article}
\usepackage{array}
\begin{document}
\begin{tabular} {| >{\ttfamily}l | p{5cm} |}
\hline
\multicolumn{2}{|l|}{Sample Table} \\ \hline
left a & right a \\ \hline
left b & right b \\ \hline
left c & right c \\ \hline
\end{tabular}
\end{document}