summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/tabulars-e/06-00-32.ltx2
blob: f121e9baf9fb76e905d226256ac62e7b7b4eb09d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
%% 
%%  A DANTE-Edition example
%% 
%%  Example 06-00-32 on page 196.
%% 
%%  Copyright (C) 2010 Herbert Voss
%% 
%%  It may be distributed and/or modified under the conditions
%%  of the LaTeX Project Public License, either version 1.3
%%  of this license or (at your option) any later version.
%% 
%%  See http://www.latex-project.org/lppl.txt for details.
%% 
%% 
%% ==== 
% Show page(s) 1,2
%% 
\documentclass[]{article}
\pagestyle{empty}
\setlength\textwidth{183.78818pt}
\usepackage[utf8]{inputenc}% adapt maybe
\usepackage[paper=70mm:85mm,pagesize]{typearea}
\usepackage[utf8]{inputenc}% adapt maybe
\usepackage[english]{babel}
\setlength\parindent{0pt}
\usepackage{etex}           % to be able to use labels
\usepackage{ltxtable}
\usepackage[savepos,user]{zref}  % to save the current position
\usepackage{fltpoint}       % floating point arithmetics
\usepackage{calc}           % for the \widthof command
\usepackage{numprint}       % formatted output of numbers
\usepackage{eurosym}        % Euro sign
% global settings for numprint
\npstyleenglish     % English number formatting
\nprounddigits{2}   % two decimal places
\npreplacenull{---} % hyphen instead of decimal zeros

%%%%%%%%%%%%%%commands to calculate the intermediate sums%%%%%%%%%%%%%%%%%%%%
\newcommand*\intsum{0}
\newcommand*\resetintsum{\global\def\intsum{0}}
\newcommand*\addintsum[1]{\fpAdd{\intsum}{\intsum}{#1}%
                                 \global\let\intsum\intsum}
\newcommand*\printval[1]{\numprint{#1}}

%%%%%%%%PlainTeX hack for positioning of intermediate sums%%%%%%%%%%%%%%%
\makeatletter  % allow the at sign in variables
% provide variables
  \newdimen\drx
  \newdimen\dry
  \newmarks\ltm@marks
  \def\ltm@setmarks#1{\marks\ltm@marks{#1}}
  \def\ltm@getmarks{\botmarks\ltm@marks}

% calculate the current value of the intermediate sum and save it
\newcommand*{\Val}[1]{%
  \printval{#1}%   immediate output of the value
  \addintsum{#1}%  add the passed value to the intermediate sum
  \expandafter\ltm@setmarks\expandafter{\intsum}% save intermediate sum
}

% save current position
\newcommand*{\MarkIntSumPos}{%
  \leavevmode
     \zsavepos{zwsumpos\thepage}%
     \zrefused{zwsumpos\thepage}}

% output intermediate sum
\def\ltm@insertfoot#1{%
    \vbox to\z@{%
      \vss
      \hb@xt@\z@{%
        \color@begingroup
            \zsavepos{tabende\thepage}%   % save current position
            \drx=0sp
            \dry=0sp
            % subtract current position and add saved one
            \advance \drx by -\zposx{tabende\thepage}sp
            \advance \drx by \zposx{zwsumpos\thepage}sp
            \advance \dry by -\zposy{tabende\thepage}sp
            \advance \dry by \zposy{zwsumpos\thepage}sp
            \smash{\kern\drx\raise\dry%
                   \hbox{\makebox[\widthof{ \euro}][r]{%
                   \printval{#1} \euro}}%
                   }
        \color@endgroup
      }%
    }%
}

% output of the carry
% like output of the intermediate sum, but without saved position
\def\ltm@inserthead#1{%
    \vbox to\z@{%
      \vss
      \hb@xt@\z@{%
        \color@begingroup
            \drx=0sp
            \dry=0sp
            % subtract position of end of table
            \advance \drx by -\zposx{tabende\thepage}sp
            \advance \drx by \zposx{zwsumpos\thepage}sp
            \advance \dry by -\zposy{tabende\thepage}sp
            \advance \dry by \zposy{zwsumpos\thepage}sp
            \smash{\kern\drx\raise\dry%
                   % The actual output. Right-aligned and translated by the
                   % width of the Euro sign.
                   \hbox{\makebox[\widthof{ \euro}][r]{%
                   \printval{#1} \euro}}%
                   }
        \color@endgroup
      }%
    }%
}

\def\ltm@lastfoot{\ltm@insertfoot\ltm@getmarks}
\def\ltm@foot{\ltm@insertfoot{\ltm@getmarks}}
\def\ltm@head{\ltm@inserthead{\ltm@getmarks}}

% overwrite the output routines of longtable
\def\LT@output{%
  \ifnum\outputpenalty <-\@Mi
    \ifnum\outputpenalty > -\LT@end@pen
      \LT@err{floats and marginpars %
              not allowed in a longtable}\@ehc
    \else
      \setbox\z@\vbox{\unvbox\@cclv}%
      \ifdim \ht\LT@lastfoot>\ht\LT@foot
        \dimen@\pagegoal
        \advance\dimen@-\ht\LT@lastfoot
        \ifdim\dimen@<\ht\z@
          \setbox\@cclv\vbox{%
            \unvbox\z@\copy\LT@foot\ltm@foot\vss
          }%
          \@makecol
          \@outputpage
          \setbox\z@\vbox{\box\LT@head}%
        \fi
      \fi
      \global\@colroom\@colht
      \global\vsize\@colht
      \vbox{%
        \unvbox\z@
        \box\ifvoid\LT@lastfoot
          \LT@foot\ltm@foot
        \else
          \LT@lastfoot\ltm@lastfoot
        \fi
      }%
    \fi
  \else
    \setbox\@cclv\vbox{%
      \unvbox\@cclv\copy\LT@foot\ltm@foot\vss
    }%
    \@makecol
    \@outputpage
    \global\vsize\@colroom
    \copy\LT@head\ltm@head
  \fi
}
\makeatother    % disallow at sign in variables
%%%%%%%%%%%%%%%%%%%%end plaintex hack%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\usepackage{longtable}

\begin{document}
\resetintsum
\begin{longtable}{p{0.7\linewidth}r}
  left & right
\endfirsthead
  carry & \\
\endhead
  intermediate sum: & \MarkIntSumPos \\
\endfoot
  sum: &\MarkIntSumPos \\
\endlastfoot
  An arbitrary introductory text at the start of the column\ldots.
    & \Val{1,00} \\
  b & \Val{2,1}  \\
  c & \Val{3,4}  \\
  d & \Val{4,5}  \\
  e & \Val{5,6}  \\
  f & \Val{6,7}  \\
  g & \Val{7,8}  \\
  h & \Val{8,9}  \\
  i & \Val{9,42} \\
  j & \Val{10,88}\\
  k & \Val{15,76}
\end{longtable}
\end{document}