高级 T 型帐户示例

高级 T 型帐户示例

我想生成一个“新命令”来为论文生成 T 帐户(如附图所示),但无法完成表格。到目前为止,我已经使用了此处的想法会计 T 型账户方案但事实并非如此。尤其是标题中 3 列的对齐设计,而下面有 4 列,这让我有些困惑。有人能给我提示如何实现吗?

谢谢

在此处输入图片描述

答案1

此代码应该可以完成您想要的操作:

{\sffamily
\begin{tabular}{@{}lllr|lllr@{}}
Dr & \multicolumn{6}{c}{Bank} & Cr \\
\hline 
&&& \$ &&&& \$ \\
Apr & 1 & Balance b/f &4{,}300 & Apr & 9 & Baking equipment & 12{,}000 \\
......
\end{tabular}}

答案2

只是为了好玩。

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn

\NewDocumentCommand{\Taccount}{m}
 {
  \str_clear:N \l__aerioeus_taccount_lmonth_str
  \str_clear:N \l__aerioeus_taccount_rmonth_str
  \clist_map_function:nN { #1 } \aerioeus_taccount_entry:n
  \begin{tabular}{@{}c|c@{}}
  \multicolumn{2}{@{}c@{}}{\makebox[0pt][l]{Dr}\hfill Bank\hfill\makebox[0pt][r]{Cr}}
  \\
  \hline
  \begin{tabular}[t]{@{}l@{~}r@{~}lr}
  &&&\multicolumn{1}{c}{\$}\\
  \l__aerioeus_taccount_left_tl
  \end{tabular}
  &
  \begin{tabular}[t]{l@{~}r@{~}lr@{}}
  &&&\multicolumn{1}{c}{\$}\\
  \l__aerioeus_taccount_right_tl
  \end{tabular}
  \end{tabular}
 }

\tl_new:N \l__aerioeus_taccount_left_tl
\tl_new:N \l__aerioeus_taccount_right_tl
\str_new:N \l__aerioeus_taccount_lmonth_str
\str_new:N \l__aerioeus_taccount_rmonth_str

\cs_new_protected:Nn \aerioeus_taccount_entry:n
 {
  \__aerioeus_taccount_entry:n #1
 }

\cs_new_protected:Nn \__aerioeus_taccount_entry:n
 {
  \str_case:nn { #1 }
   {
    {+}{ \__aerioeus_taccount_entry:NNnnnn \l__aerioeus_taccount_left_tl \l__aerioeus_taccount_lmonth_str }
    {-}{ \__aerioeus_taccount_entry:NNnnnn \l__aerioeus_taccount_right_tl \l__aerioeus_taccount_rmonth_str }
   }
 }

\cs_new_protected:Nn \__aerioeus_taccount_entry:NNnnnn
 {% #1 = tl, #2 = str, #3 = month, #4 = day, #5 = desc, #6 = amount
  \str_if_eq_x:nnTF { #3 } { #2 }
   {% month is the same as the previous entry
    \tl_put_right:Nn #1 { & #4 & #5 & #6 \\ }
   }
   {% months differ, update the current one
    \str_set:Nn #2 { #3 }
    \tl_put_right:Nn #1 { #3 & #4 & #5 & #6 \\ }
   }
 }

\ExplSyntaxOff

\begin{document}

\begin{center}
\Taccount{
  +{Apr}{1}{Balance b/f}{4,300},
  +{Apr}{1}{Capital}{15,000},
  +{Apr}{7}{Loan}{5,000},
  -{Apr}{9}{Baking equipment}{12,000},
  -{Apr}{15}{Drawing}{500},
  +{Apr}{17}{Services rendered}{10,500},
  +{Apr}{19}{Debtors}{5,000},
  -{Apr}{19}{Salaries}{4,000},
  -{May}{13}{Creditors}{200},
  -{May}{13}{Loan}{4,000},
}
\end{center}

\end{document}

如您所见,左列的条目标记为+,右列的条目-则按顺序输入。行末的逗号是必不可少的。

检查每个条目:+-决定是否将其余四个参数添加到左子表或右子表。收集数据后,输出表格。

在此处输入图片描述

相关内容