首先我要说的是,我知道有一个发票包。它不适用于我的设置,我希望进行更多的自定义。因此,为了复制该包,我创建了一个新环境,并在该环境中创建了一个新命令。不幸的是,它似乎不起作用,我不知道为什么。
以下是 MWE:
\documentclass{article}
\usepackage{calc}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage[table]{xcolor}
\newenvironment{invoice}{%
\newcounter{total}%
\newcommand*{\additem}[2]{\addtocounter{total}{##2}##1&&##2}%
\tabularx{\linewidth}{Xc@{}r}
\toprule
\textbf{DESCRIPTION} && \textbf{AMOUNT}\\
\midrule}{%
\bottomrule
\newcounter{wholetotal}\setcounter{wholetotal}{\value{total}/100}
\newcounter{fractotal}\setcounter{fractotal}{\value{total}-\value{wholetotal}*100}
\multicolumn{1}{r}{\textbf{TOTAL:}} & \cellcolor{blue!10!white} \$ & \cellcolor{blue!10!white} \arabic{wholetotal}.\ifnum\value{fractotal}<10 0\fi\arabic{fractotal} \\
\endtabularx
Please pay the amount in full by check made out to ``Company''}
\begin{document}
\begin{invoice}
\additem{Data collection}{1500}
\end{invoice}
\end{document}
我收到了很多错误,但这里有一个示例:
test.tex|25 error| Misplaced \noalign.
test.tex|25 error| Missing } inserted.
test.tex|25 error| Missing \endgroup inserted.
test.tex|25 error| Missing } inserted.
test.tex|25 error| Missing } inserted.
test.tex|25 error| Missing } inserted.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Missing { inserted.
test.tex|25 error| Missing { inserted.
test.tex|25 error| Missing } inserted.
test.tex|25 error| Missing } inserted.
test.tex|25 error| Missing } inserted.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
test.tex|25 error| Missing \cr inserted.
test.tex|25 error| Misplaced \cr.
答案1
已经有一个invoice
包,但是这里...我们不使用它;-)
不要\newcounter{...}
在假定被多次调用的环境中说。
主要错误是缺少\tabularnewline
(或\\
)语句以及可以通过 来避免的对齐错误\noalign{...}
,因为\multicolumn
预计位于单元格中的第一个项目中(正如 Werner 在下面所述 ;-))
\documentclass{article}
\usepackage{calc}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage[table]{xcolor}
\newcounter{total}
\newcounter{wholetotal}
\newcounter{fractotal}
\newenvironment{invoice}{%
\setcounter{total}{0}
\setcounter{wholetotal}{0}
\setcounter{fractotal}{0}
\newcommand*{\additem}[2]{\addtocounter{total}{##2} ##1&&##2 \tabularnewline}%
\tabularx{\linewidth}{Xc@{}r}
\toprule
\textbf{DESCRIPTION} && \textbf{AMOUNT}\\
\midrule
}{%
\bottomrule
\tabularnewline
\noalign{\setcounter{wholetotal}{\value{total}/100}}
\noalign{\setcounter{fractotal}{\value{total}-\value{wholetotal}*100}}
\multicolumn{1}{r}{\textbf{TOTAL:}} & \cellcolor{blue!10!white} \textdollar & \cellcolor{blue!10!white} \arabic{wholetotal}.\ifnum\value{fractotal}<10 0\fi\arabic{fractotal} \\
\tabularnewline% More space at the end
\endtabularx
Please pay the amount in full by check made out to ``Company''}
\begin{document}
\begin{invoice}
\additem{Data collection}{1500}%{00}
\additem{LaTeX book}{50000}%{00}
\end{invoice}
\end{document}