我正在使用longtable
和fp
包在文档中创建发票scrlttr2
。我使用了\entry
自定义命令来创建累计总计、计算税额并获得总计。问题是,在表格主体中,命令填充的所有第一个单元格\entry
前面都有多余的空白。其他单元格中都没有发生此问题!我完全不知道发生了什么。
\multicolumn
我尝试过在 的定义中使用 强制保留内容\entry
,但 LaTeX 会抛出错误。同样,我也尝试过\begin{flushleft} ... \end{flushleft}
,但无济于事。任何帮助都将不胜感激。在下面找到 MWE。
\documentclass[english, 12pt, a4]{scrlttr2}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{longtable}
\usepackage[nomessages]{fp}
\newcommand\T{\rule{0pt}{2.6ex}} % Top strut after hline
\newcommand\B{\rule[-1.0ex]{0pt}{0pt}} % Bottom strut before hline
%%Longtable \entry and fp commands
\FPset{itemTotal}{0}
\FPset{vat}{0.17}
\newcommand{\entry}[5]{%
\FPeval{itemTotal}{itemTotal+#5}% Add to each itemTotal
\FPmul{\tax}{\vat}{\itemTotal}
\FPadd{\grandTotal}{\tax}{\itemTotal}
\xdef\grandTotal{\grandTotal}
\xdef\tax{\tax}
\xdef\itemTotal{\itemTotal}% Make definition \global
#1 & #2 & #3 & #4 & #5% Set entry
}
\begin{document}
\begin{letter}{%
Bill To:\\
Someone\\
Some House\\
Somewhere Ville
}
\KOMAoptions{parskip=yes}
\opening{\null}
\begin{center}
\begin{longtable}{|llrrr|}
\hline
\textbf{Date} & \textbf{Description} & \textbf{Unit Price} & \textbf{Units} & \textbf{Item Total}\T\B\\
\hline
\endhead
\entry{10/03/2016}{Something I did}{10/hour}{6}{60.00}\T\\
\entry{12/03/2016}{Something I claim I did}{50/hour}{5}{250.00}\B\\
\hline\hline
\multicolumn{4}{|r}{Subtotal}&\FPround{\itemTotal}{\itemTotal}{2}\itemTotal\T\\*
\multicolumn{4}{|r}{VAT 17.0\%}&\FPround{\tax}{\tax}{2}\tax\\*[5pt]
\multicolumn{4}{|r}{\textbf{Grand Total}}&\FPround{\grandTotal}{\grandTotal}{2}\grandTotal\B\\*
\hline
\end{longtable}
\end{center}
\closing{\null}
\end{letter}
\end{document}
答案1
结尾处有很多遗漏%
。否则都是空格
\newcommand{\entry}[5]{%
\FPeval{itemTotal}{itemTotal+#5}% Add to each itemTotal
\FPmul{\tax}{\vat}{\itemTotal}%
\FPadd{\grandTotal}{\tax}{\itemTotal}%
\xdef\grandTotal{\grandTotal}%
\xdef\tax{\tax}%
\xdef\itemTotal{\itemTotal}% Make definition \global
#1 & #2 & #3 & #4 & #5% Set entry
}