我想要创建下表:
MWE如下:
\documentclass{article}
\begin{document}
\begin{tabular}{|c|c|c|c|}
\hline
% after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
Name of the Service & Description & Input & Output \\
creditAccount & To credit a bank account & \begin{enumerate}\item Account Number \item Amount \end{enumerate} & \begin{enumerate}\item Message – Whether the credit was successful or not \item Current Account Balance
\end{enumerate} \\
& & & \\
& & & \\
& & & \\
& & & \\
& & & \\
\hline
\end{tabular}
\end{document}
我的方法有什么问题?
答案1
以下提供了所需的表格布局(无颜色):
\documentclass{article}
\usepackage[margin=1in]{geometry}% Just for this example
\usepackage{tabularx,array,booktabs}
\newcolumntype{N}{@{}>{\stepcounter{enumi}\theenumi.~}l@{}}
\newcolumntype{M}{@{}>{\stepcounter{enumi}\theenumi.~}p{\linewidth}@{}}
\newenvironment{listenv}
{\setcounter{enumi}{0}% Reset list counter
\begin{tabular}[t]}
{\end{tabular}}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{ >{\centering\arraybackslash}X *{3}{X} }
\toprule
\textbf{Name of the Service} & \textbf{Description} & \textbf{Input} & \textbf{Output} \\
\midrule
% Credit Account =====
creditAccount & To credit a bank account & \begin{listenv}{N}
Account Number \\ Amount
\end{listenv} & \begin{listenv}{M}
Message -- Whether the credit was successful or not \\
Current Account Balance
\end{listenv} \\
% Credit Transaction Details =====
creditTransactionDetails & To get the details of the last credit transaction & \begin{listenv}{N}
Account Number
\end{listenv} &
Message -- With the amount last credited in the account \\
% Debit Account =====
debitAccount & To debit from a bank account & \begin{listenv}{N}
Account Number \\ Amount
\end{listenv} & \begin{listenv}{M}
Message -- Whether the debit was successful or not \\
Current Account Balance
\end{listenv} \\
% Debit Transaction Details =====
debitTransactionDetails & To get the details of the last debit transaction & \begin{listenv}{N}
Account Number
\end{listenv} &
Message -- With the amount last debited in the account \\
% Get Account Balance =====
getAccountBalance & To get the balance in the account & \begin{listenv}{N}
Account Number
\end{listenv} &
Message -- With the balance in the account \\
% Get Credit Card Amount =====
getCreditCardAmount & To get amount spent through credit card & \begin{listenv}{N}
Account Number
\end{listenv} &
Message -- With the amount spent with Credit Card \\
\bottomrule
\end{tabularx}
\end{document}
使用以下方式手动插入枚举array
的>{...}
指令。listenv
自动执行重置计数器的过程enumi
- 通常用于enumerate
列表的第一级。