使用tabular
,可选参数[t]
可以将对齐方式设置为顶部,这在将表格放在列表项中时非常方便。这会将表格的第一行与列表编号对齐。
有没有什么办法可以做到这一点tabularx
?
\documentclass{article}
\usepackage{tabularx}
\newenvironment{cheeselist}
{\begin{enumerate}}
{\end{enumerate}}
\newenvironment{cheese}
{\item \tabularx{\linewidth}{l X}}
{\endtabularx}
\newcommand{\cheesename}[1]{Name & #1\\}
\newcommand{\cheesecolor}[1]{Color & #1\\}
\begin{document}
\begin{cheeselist}
\begin{cheese}
\cheesename{Cheddar}
\cheesecolor{Yellow or White}
\end{cheese}
\begin{cheese}
\cheesename{Swiss (Emmentaler)}
\cheesecolor{White}
\end{cheese}
\end{cheeselist}
\end{document}
答案1
是的,语法是
\begin{tabularx}{<width>}[<pos>]{<col spec>}
% tabular content
\end{tabularx}
这是你的例子:
\documentclass{article}
\usepackage{tabularx}
\newenvironment{cheeselist}
{\begin{enumerate}}
{\end{enumerate}}
\newenvironment{cheese}
{\item \tabularx{\linewidth}[t]{l X}}
{\endtabularx}
\newcommand{\cheesename}[1]{Name & #1\\}
\newcommand{\cheesecolor}[1]{Color & #1\\}
\begin{document}
\begin{cheeselist}
\begin{cheese}
\cheesename{Cheddar}
\cheesecolor{Yellow or White}
\end{cheese}
\begin{cheese}
\cheesename{Swiss (Emmentaler)}
\cheesecolor{White}
\end{cheese}
\end{cheeselist}
\end{document}