我想将表格第二列的所有名称都斜体化,但目前我发现唯一的方法是\textit{}
在每个单元格中使用,即:
\documentclass{article}
\begin{document}
\begin{table}
\begin{tabular}{lll}
PFT & Scientific Name & Common Name\\
PFT1 & & \\
& \textit{Elymus repens} & quackgrass\\
& \textit{Koeleria macrantha} & prairie Junegrass\\
& \textit{Elymus canadensis} & Canada wildrye\\
%....
\end{tabular}
\label{tab:foo}
\caption{test caption}
\end{table}
\end{document}
有没有更简单/更优雅的方法来做到这一点?
答案1
\itshape
对于第二列使用数组包指定,\multicolumn
对于表头使用命令取消效果。
\documentclass{article}
\usepackage{array}
\begin{document}
\begin{tabular}{l>{\itshape}ll}
PFT & \multicolumn{1}{l}{Scientific Name} & Common Name\\
PFT1 & & \\
& Elymus repens & quackgrass\\
& Koeleria macrantha & prairie Junegrass\\
& Elymus canadensis & Canada wildrye\\
\end{tabular}
\end{document}
答案2
相反\multicolumn{1}{l}{Scientific Name}
(作为步调一致 建议)你可以\normaltext{Scientific Name}
按如下方式使用:
\documentclass{article}
\usepackage{array}
\begin{document}
\begin{tabular}{l>{\itshape}ll}
PFT & \normaltext{Scientific Name} & Common Name\\
PFT1 & & \\
& Elymus repens & quackgrass\\
& Koeleria macrantha & prairie Junegrass\\
& Elymus canadensis & Canada wildrye\\
\end{tabular}
\end{document}
答案3
在{NiceTabular}
中nicematrix
,您有一个内置的行计数器,称为iRow
(它是 LaTeX 计数器,而不是 TeX 计数器)。因此,很容易创建一个仅在第一行之后应用的列说明符。
\documentclass{article}
\usepackage{ifthen}
\usepackage{nicematrix}
\begin{document}
\newcolumntype{B}[1]{>{\ifthenelse{\value{iRow}>1}{#1}{}}}
\begin{NiceTabular}{lB{\itshape}ll}
PFT & Scientific Name & Common Name \\
PFT1 & & \\
& Elymus repens & quackgrass \\
& Koeleria macrantha & prairie Junegrass \\
& Elymus canadensis & Canada wildrye \\
\end{NiceTabular}
\end{document}
答案4
一个简单的解决方案与tblr
环境tabularray
包裹:
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{table}
\centering
\begin{tblr}{
colspec = {lll},
cell{2-Z}{2} = {font=\itshape}, % Z stands for the last
hlines,
}
PFT & Scientific Name & Common Name \\
PFT1 & & \\
& Elymus repens & quackgrass \\
& Koeleria macrantha & prairie Junegrass \\
& Elymus canadensis & Canada wildrye \\
\end{tblr}
\label{tab:foo}
\caption{test caption}
\end{table}
\end{document}