对齐小计小时数的变化:

对齐小计小时数的变化:

使用发票模板时

https://www.latextemplates.com/template/invoice

小计和应付余额的美元金额与单个咨询服务条目不一致(即,美元和美分之间的点不一致)。

如何修改乳胶源或 cls 文件以使发票中的所有美元金额一致?

一个简单的例子是模板的示例 latex 文件,它在帖子开头的链接中产生输出:

\documentclass{invoice} % Use the custom invoice class (invoice.cls)

\def \tab {\hspace*{3ex}} % Define \tab to create some horizontal white space

\begin{document}


\hfil{\Huge\bf Initech Inc.}\hfil % Company providing the invoice
\bigskip\break % Whitespace
\hrule % Horizontal line

123 Broadway \hfill (000) 111-1111 \\ % Your address and contact information
City, State 12345 \hfill [email protected]
\\ \\
{\bf Invoice To:} \\
\tab James Smith \\ % Invoice recipient
\tab Generic Corporation \\ % Recipient's company

{\bf Date:} \\
\tab \today \\ % Invoice date


\begin{invoiceTable}

\feetype{Consulting Services} % Fee category description

\hourrow{October 3, 2012}{8}{12} 

\hourrow{October 4, 2012}{6.5}{12}

\hourrow{October 5, 2012}{5.25}{12}

\hourrow{October 10, 2012}{9.75}{20}

\hourrow{October 11, 2012}{5}{12.51}

%------------------------------------------------

\feetype{Accounting Services} % Fee category description

\hourrow{October 10, 2012}{2}{80}
\hourrow{October 11, 2012}{1}{80}

\subtotal % Prints a subtotal, can be used multiple times

%------------------------------------------------

\feetype{Hosting Expenses} % Fee category description

\feerow{Web Hosting: October, 2012}{60} % A flat fee service, note there is no hourly rate for this

\end{invoiceTable}



\end{document}

答案1

在这种特殊情况下,我建议您将原始文件复制invoice.cls到新文件中并将其命名为myinvoice.cls

导致您犯错的原因是%此类代码中缺少某些内容。这意味着您在 subtotal 的数字末尾得到了您不想要的空白。该空白是数字未对齐的原因...

在以下位置搜索代码myinvoice.cls

\newcommand{\subtotalNoStar}{
    {\bf Subtotal} & {\bf \total{subhours} hours} &  & {\bf \$\total{subcost}}
    \setcounter{subcost}{0}
    \setcounter{subhours}{0}
    \\*[1.5ex]
}
\newcommand{\subtotalStar}{
    {\bf Subtotal} & & & {\bf \$\total{subcost}}
    \setcounter{subcost}{0}
    \\*[1.5ex]
} 

并将其更改为(请参阅<===重要的代码更改):

\newcommand{\subtotalNoStar}{% <====================================
    {\bf Subtotal} & {\bf \total{subhours} hours} &  & {\bf \$\total{subcost}}% <========
    \setcounter{subcost}{0}% <======================================
    \setcounter{subhours}{0}% <=====================================
    \\*[1.5ex]
}
\newcommand{\subtotalStar}{% <======================================
    {\bf Subtotal} & & & {\bf \$\total{subcost}}% <=================
    \setcounter{subcost}{0}% <======================================
    \\*[1.5ex]
}

因此你将得到一个已更改的文件myinvoice.cls

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  Copyright (c) 2011 Trey Hunner                                          %
%                                                                          %
%  Permission is hereby granted, free of charge, to any person obtaining   %
%  a copy of this software and associated documentation files (the         %
%  "Software"), to deal in the Software without restriction, including     %
%  without limitation the rights to use, copy, modify, merge, publish,     %
%  distribute, sublicense, and/or sell copies of the Software, and to      %
%  permit persons to whom the Software is furnished to do so, subject to   %
%  the following conditions:                                               %
%                                                                          %
%  The above copyright notice and this permission notice shall be          %
%  included in all copies or substantial portions of the Software.         %
%                                                                          %
%  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,         %
%  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF      %
%  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND                   %
%  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE  %
%  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION  %
%  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION   %
%  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.         %
%                                                                          %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ProvidesClass{invoice}

\LoadClass[12pt]{article}

\usepackage[letterpaper,hmargin=0.79in,vmargin=0.79in]{geometry}
\usepackage[parfill]{parskip} % Do not indent paragraphs
\usepackage{fp} % Fixed-point arithmetic
\usepackage{calc} % Counters for totaling hours and cost
\usepackage{longtable}

\pagestyle{empty} % No page numbers
\linespread{1.5} % Line spacing

\setlength{\doublerulesep}{\arrayrulewidth} % Double rules look like one thick one

% Command for setting a default hourly rate
\newcommand{\feetype}[1]{
    \textbf{#1}
    \\
}

% Counters for totaling up hours and dollars
\newcounter{hours} \newcounter{subhours} \newcounter{cost} \newcounter{subcost}
\setcounter{hours}{0} \setcounter{subhours}{0} \setcounter{cost}{0} \setcounter{subcost}{0}

% Formats inputed number with 2 digits after the decimal place
\newcommand*{\formatNumber}[1]{\FPround{\cost}{#1}{2}\cost} %

% Returns the total of counter
\newcommand*{\total}[1]{\FPdiv{\t}{\arabic{#1}}{1000}\formatNumber{\t}}

% Create an invoice table
\newenvironment{invoiceTable}{
    % Create a new row from title, unit quantity, unit rate, and unit name
    \newcommand*{\unitrow}[4]{%
         \addtocounter{cost}{1000 * \real{##2} * \real{##3}}%
         \addtocounter{subcost}{1000 * \real{##2} * \real{##3}}%
         ##1 & \formatNumber{##2} ##4 & \$\formatNumber{##3} & \$\FPmul{\cost}{##2}{##3}\formatNumber{\cost}%
         \\
    }
    % Create a new row from title and expense amount
    \newcommand*{\feerow}[2]{%
         \addtocounter{cost}{1000 * \real{##2}}%
         \addtocounter{subcost}{1000 * \real{##2}}%
         ##1 & & \$\formatNumber{##2} & \$\FPmul{\cost}{##2}{1}\formatNumber{\cost}%
         \\
    }

    \newcommand{\subtotalNoStar}{%
        {\bf Subtotal} & {\bf \total{subhours} hours} &  & {\bf \$\total{subcost}}%
        \setcounter{subcost}{0}%
        \setcounter{subhours}{0}%
        \\*[1.5ex]
    }
    \newcommand{\subtotalStar}{%
        {\bf Subtotal} & & & {\bf \$\total{subcost}}%
        \setcounter{subcost}{0}%
        \\*[1.5ex]
    }
    \newcommand{\subtotal}{
         \hline
         \@ifstar
         \subtotalStar%
         \subtotalNoStar%
    }

    % Create a new row from date and hours worked (use stored fee type and hourly rate)
    \newcommand*{\hourrow}[3]{%
        \addtocounter{hours}{1000 * \real{##2}}%
        \addtocounter{subhours}{1000 * \real{##2}}%
        \unitrow{##1}{##2}{##3}{hours}%
    }
    \renewcommand{\tabcolsep}{0.8ex}
    \setlength\LTleft{0pt}
    \setlength\LTright{0pt}
    \begin{longtable}{@{\extracolsep{\fill}\hspace{\tabcolsep}} l r r r }
    \hline
    {\bf Description of Services} & \multicolumn{1}{c}{\bf Quantity} & \multicolumn{1}{c}{\bf Unit Price} & \multicolumn{1}{c}{\bf Amount} \\*
    \hline\hline
    \endhead
}{
    \hline\hline\hline
    {\bf Balance Due} & & & {\bf \$\total{cost}} \\
    \end{longtable}
}

您可以使用新的 documentclass 来使用它,myinvoice例如:

\documentclass{myinvoice} % <===========================================

\def \tab {\hspace*{3ex}} % Define \tab to create some horizontal white space


\begin{document}

\hfil{\Huge\bf Initech Inc.}\hfil % Company providing the invoice
\bigskip\break % Whitespace
\hrule % Horizontal line

123 Broadway \hfill (000) 111-1111 \\ % Your address and contact information
City, State 12345 \hfill [email protected]
\\ \\
{\bf Invoice To:} \\
\tab James Smith \\ % Invoice recipient
\tab Generic Corporation \\ % Recipient's company

{\bf Date:} \\
\tab \today \\ % Invoice date


\begin{invoiceTable}

\feetype{Consulting Services} % Fee category description

\hourrow{October 3, 2012}{8}{12} 

\hourrow{October 4, 2012}{6.5}{12}

\hourrow{October 5, 2012}{5.25}{12}

\hourrow{October 10, 2012}{9.75}{20}

\hourrow{October 11, 2012}{5}{12.51}

%------------------------------------------------

\feetype{Accounting Services} % Fee category description

\hourrow{October 10, 2012}{2}{80}
\hourrow{October 11, 2012}{1}{80}

\subtotal % Prints a subtotal, can be used multiple times

%------------------------------------------------

\feetype{Hosting Expenses} % Fee category description

\feerow{Web Hosting: October, 2012}{60} % A flat fee service, note there is no hourly rate for this

\end{invoiceTable}



\end{document}

得到的 pdf 格式如下:

生成的发票

对齐小计小时数的变化:

您需要更改为\subtotalNoStar(移至hours数字之前):

\newcommand{\subtotalNoStar}{%
    {\bf Subtotal} & {\bf hours \total{subhours}} &  & {\bf \$\total{subcost}}% <===============
    \setcounter{subcost}{0}%
    \setcounter{subhours}{0}%
    \\*[1.5ex]
}

并且您需要更改命令\unitrow(将##4之前\formatNumber{##2}使用的小时数移至:

\newcommand*{\unitrow}[4]{%
     \addtocounter{cost}{1000 * \real{##2} * \real{##3}}%
     \addtocounter{subcost}{1000 * \real{##2} * \real{##3}}%
%        ##1 & \formatNumber{##2} ##4 & \$\formatNumber{##3} & \$\FPmul{\cost}{##2}{##3}\formatNumber{\cost}%
         ##1 &  ##4 \formatNumber{##2} & \$\formatNumber{##3} & \$\FPmul{\cost}{##2}{##3}\formatNumber{\cost}% <====================

随着改变myinvoice.cls

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  Copyright (c) 2011 Trey Hunner                                          %
%                                                                          %
%  Permission is hereby granted, free of charge, to any person obtaining   %
%  a copy of this software and associated documentation files (the         %
%  "Software"), to deal in the Software without restriction, including     %
%  without limitation the rights to use, copy, modify, merge, publish,     %
%  distribute, sublicense, and/or sell copies of the Software, and to      %
%  permit persons to whom the Software is furnished to do so, subject to   %
%  the following conditions:                                               %
%                                                                          %
%  The above copyright notice and this permission notice shall be          %
%  included in all copies or substantial portions of the Software.         %
%                                                                          %
%  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,         %
%  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF      %
%  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND                   %
%  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE  %
%  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION  %
%  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION   %
%  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.         %
%                                                                          %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ProvidesClass{myinvoice} % <===========================================

\LoadClass[12pt]{article}

\usepackage[letterpaper,hmargin=0.79in,vmargin=0.79in]{geometry}
\usepackage[parfill]{parskip} % Do not indent paragraphs
\usepackage{fp} % Fixed-point arithmetic
\usepackage{calc} % Counters for totaling hours and cost
\usepackage{longtable}

\pagestyle{empty} % No page numbers
\linespread{1.5} % Line spacing

\setlength{\doublerulesep}{\arrayrulewidth} % Double rules look like one thick one

% Command for setting a default hourly rate
\newcommand{\feetype}[1]{
    \textbf{#1}
    \\
}

% Counters for totaling up hours and dollars
\newcounter{hours} \newcounter{subhours} \newcounter{cost} \newcounter{subcost}
\setcounter{hours}{0} \setcounter{subhours}{0} \setcounter{cost}{0} \setcounter{subcost}{0}

% Formats inputed number with 2 digits after the decimal place
\newcommand*{\formatNumber}[1]{\FPround{\cost}{#1}{2}\cost} %

% Returns the total of counter
\newcommand*{\total}[1]{\FPdiv{\t}{\arabic{#1}}{1000}\formatNumber{\t}}

% Create an invoice table
\newenvironment{invoiceTable}{
    % Create a new row from title, unit quantity, unit rate, and unit name
    \newcommand*{\unitrow}[4]{%
         \addtocounter{cost}{1000 * \real{##2} * \real{##3}}%
         \addtocounter{subcost}{1000 * \real{##2} * \real{##3}}%
%         ##1 & \formatNumber{##2} ##4 & \$\formatNumber{##3} & \$\FPmul{\cost}{##2}{##3}\formatNumber{\cost}%
         ##1 &  ##4 \formatNumber{##2} & \$\formatNumber{##3} & \$\FPmul{\cost}{##2}{##3}\formatNumber{\cost}% <====================

         \\
    }
    % Create a new row from title and expense amount
    \newcommand*{\feerow}[2]{%
         \addtocounter{cost}{1000 * \real{##2}}%
         \addtocounter{subcost}{1000 * \real{##2}}%
         ##1 & & \$\formatNumber{##2} & \$\FPmul{\cost}{##2}{1}\formatNumber{\cost}%
         \\
    }

    \newcommand{\subtotalNoStar}{%
        {\bf Subtotal} & {\bf hours \total{subhours}} &  & {\bf \$\total{subcost}}% <===============
        \setcounter{subcost}{0}%
        \setcounter{subhours}{0}%
        \\*[1.5ex]
    }
    \newcommand{\subtotalStar}{%
        {\bf Subtotal} & & & {\bf \$\total{subcost}}%
        \setcounter{subcost}{0}%
        \\*[1.5ex]
    }
    \newcommand{\subtotal}{
         \hline
         \@ifstar
         \subtotalStar%
         \subtotalNoStar%
    }

    % Create a new row from date and hours worked (use stored fee type and hourly rate)
    \newcommand*{\hourrow}[3]{%
        \addtocounter{hours}{1000 * \real{##2}}%
        \addtocounter{subhours}{1000 * \real{##2}}%
        \unitrow{##1}{##2}{##3}{hours}%
    }
    \renewcommand{\tabcolsep}{0.8ex}
    \setlength\LTleft{0pt}
    \setlength\LTright{0pt}
    \begin{longtable}{@{\extracolsep{\fill}\hspace{\tabcolsep}} l r r r }
    \hline
    {\bf Description of Services} & \multicolumn{1}{c}{\bf Quantity} & \multicolumn{1}{c}{\bf Unit Price} & \multicolumn{1}{c}{\bf Amount} \\*
    \hline\hline
    \endhead
}{
    \hline\hline\hline
    {\bf Balance Due} & & & {\bf \$\total{cost}} \\
    \end{longtable}
}

使用与之前相同的 mwe,你将获得以下结果:

生成的 pdf mwe two

相关内容