
Hallo,
ich möchte gern einen Brieffuß so gestalten, dass bei einem mehrseitigen Brief eine Seitenangabe gemacht wird, bei einseitigen Briefen dageben nicht.
Leider funktioniert das hier nicht:
\firstfoot{\strut%
\makebox[\textwidth][l]{%
% \@ifonlastpage
\ifnum\thepage=\value{TotPages}%
\parbox[t]{\useplength{firstfootwidth}}{%
\hrulefill \quad \raisebox{-1.95mm}{\usekomavar{imtekicon}}
}%end of parbox
\else
\parbox[t]{\useplength{firstfootwidth}}{%
\raisebox{-0.3em}{\usekomafont{pagenumber}\thepage\,/\,\ref{TotPages}} \quad \hrulefill \quad \raisebox{-1.95mm}{\usekomavar{imtekicon}}
}%end of parbox
\fi
}%end of makebox
}%end of firstfoot
Wäre sehr dankbar, wenn mir jemand Anregungen geben könnte, wie man hier am besten vorgeht, sodass man den Zähler TotPages aus dem totpages-Paket für die if-Abfrage verwenden kann...
Eigentlich sollte das nicht so kompliziert sein
Ein Beispiel gefällig?
\documentclass{scrlttr2} \usepackage{lipsum} \newcommand*{\setpagenumber}[1]{} \firstfoot{\null\hfill\setpagenumber{\thepage}\hfill\null} % Jetzt kommt der Trick (den man auch in \nextfoot verstecken kann) \makeatletter \@makeother\# \nexthead{\write\@auxout{% \protect\gdef\protect\setpagenumber#1{% #1/\thepage}}% } \catcode`\#=6 \makeatother \nextfoot{% \null\hfill\setpagenumber{\thepage}\hfill\null } \pagestyle{headings} \begin{document} \begin{letter}{Erster\\Brief} \opening{Hallo} \lipsum% Für einseitigen Brief auskommentieren \lipsum% Für einseitigen Brief auskommentieren \closing{Bye} \end{letter} \end{document}Das Komplizierteste daran ist eigentlich, dafür zu sorgen, dass beim Definieren von
\nextheaddas#1beim Schreiben der Definition in die aux-Datei nicht als aktueller erster Parameter verstanden wird. Das wird dadurch erreicht, dass der cat-code von#kurzzeitig auf other gesetzt wird. Alles andere ist eigentlich nur ein wenig Nachdenken.Problem gelöst -- Grund unklar :)
Hallo,
ein Kollege wusste Rat: weder mit
\ifnum\page=\TotPagesnoch mit
\ifnum\value{page}=\value{TotPages}funktioniert die Abfrage.
Macht man es allerdings einfach ohne dem "page"-Zähler, dann klappt es:
Wenn jetzt noch jemand weiß, warum das nur so geht, wären wir dankbar!
leider doch nicht...
Hallo,
die Lösung für das Problem ist nicht trivial, scheint es... Was in laufenden Text problemlos mit \ifnum funktioniert, klappt nicht im Fuß.
Nach langem Recherchieren funktioniert jetzt der nachfolgende Code, aber elegant ist in meinen Augen echt was anderes. Da ist ja fast so schön wie Brainfuck :)
%% definition of the custom IMTEK letter foot ================================================
\RequirePackage{totpages}
%% Unfortunately, a simple \ifnum .. \else .. \fi does not work:
% \ifnum\value{TotPages}>0
% \arabic{TotPages} - \theTotPages mehrseitig: \ref{TotPages}
% \else
% \arabic{TotPages} - \theTotPages einseitig: \ref{TotPages}
% \fi
%% from endheads.sty --------------------------------------
% Essentially these routines are code posted by Heiko Oberdiek to
% comp.text.tex. If you set a counter from a |\pageref|, that
% |\pageref| is undefined on the first run, and \TeX\ will not only
% complain about the undefined reference, but give a ``missing
% number'' error if you try to do anything with that reference, such
% as compare one page number to another. These commands enable one to
% use the |\pageref| without generating the missing number error on
% the first run.
\providecommand*{\ifrefundefined}[1]{%
\expandafter\ifx\csname r@#1\endcsname\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
\providecommand*{\@extract@ref}[2]{%
\expandafter\expandafter\expandafter#1\csname
r@#2\endcsname{}{}\@nil
}
\providecommand*{\@extractref}{%
\@extract@ref\@car
}
\providecommand*{\@extractpageref}{%
\@extract@ref\@secondcar
}
\long\def\@secondcar#1#2#3\@nil{#2}
\providecommand*{\setcounterfromref}[2]{%
\ifrefundefined{#2}{%
\protect\G@refundefinedtrue
\@latex@warning{Reference `#2' on page \thepage \space
undefined}%
\setcounter{#1}{0}%
}{%
\setcounter{#1}{\@extractref{#2}}%
}%
}
\providecommand*{\setcounterfrompageref}[2]{%
\ifrefundefined{#2}{%
\protect\G@refundefinedtrue
\@latex@warning{Reference `#2' on page \thepage \space
undefined}%
\setcounter{#1}{0}%
}{%
\setcounter{#1}{\@extractpageref{#2}}%
}%
}
\providecommand*{\numberfromref}[2]{%
\ifrefundefined{#2}{%
\protect\G@refundefinedtrue
\@latex@warning{Reference `#2' on page \thepage \space
undefined}%
0%
}{%
\@extractref{#2}%
}%
}
\providecommand*{\numberfrompageref}[2]{%
\ifrefundefined{#2}{%
\protect\G@refundefinedtrue
\@latex@warning{Reference `#2' on page \thepage \space
undefined}%
0%
}{%
\@extractpageref{#2}%
}%
}
\providecommand*{\@ifonlastpage}[2]{%
\ifrefundefined{TotPages}{%
\protect\G@refundefinedtrue
#2%
}{%
\ifnum\thepage=\@extractpageref{TotPages}#1\else #2\fi%
}%
}
%%---------------------------------------------------------
\providecommand*{\@ifsinglepagedoc}[2]{%
\ifrefundefined{TotPages}{%
\protect\G@refundefinedtrue
#2%
}{%
\ifnum\thepage=\@extractpageref{TotPages}#1\else #2\fi%
}%
}
\firstfoot{\strut%
\makebox[\textwidth][l]{%
\parbox[t]{\useplength{firstfootwidth}}{%
\@ifsinglepagedoc{%
\hrulefill \quad \raisebox{-1.95mm}{\usekomavar{imtekicon}}
}{%
\raisebox{-0.3em}{\usekomafont{pagenumber}\thepage\,/\,\ref{TotPages}} \quad \hrulefill \quad \raisebox{-1.95mm}{\usekomavar{imtekicon}}
}
}%end of parbox
}%end of makebox
}%end of firstfoot
%% definition of the custom footer for all other pages but first one
\nextfoot{\hspace*{-\oddsidemargin}\hspace{-1in}%
\hspace{\useplength{toaddrhpos}}%
\makebox[\textwidth][l]{%
\parbox[t]{\useplength{firstfootwidth}}{%
~\\[-\dp\strutbox]
\raisebox{-0.3em}{\usekomafont{pagenumber}\thepage\,/\,\ref{TotPages}} \quad \hrulefill \quad \raisebox{-1.95mm}{\usekomavar{imtekicon}}
}%end of parbox
}%end of makebox
}%end of nextfoot
%% ACHTUNG: (lt. Doku) \nexthead bzw. \nextfoot nur bei Seitenstil headings (bzw. scrheadings) in Verwendung!
%% Undokumentiert: die Elemente pagehead und pagefoot gelten *nicht* fuer \firsthead und \firstfoot!
\pagestyle{headings}
% --------------------------------------------------------------------------------------------