środa, 27 marca 2013

LaTeX: example of a complex titlepage design

Let's start from example preamble:


\documentclass[twoside]{article}
\usepackage{fancyhdr}

\pagestyle{fancy}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}

\makeatletter
%% headlines (\@shorttitle/\@shortauthorlist see below):
\fancyhead[RO]{\@shorttitle}
\fancyhead[LE]{\@shortauthorlist}

...
\makeatother

% Title (in Polish) and alternate title (in english):
\title{Hemofiltracja i~rewaskularyzacja u~pacjenta
z~zespołem sercowo-nerkowym typu 2}
\alttitle{Hemofiltration in patient with cardio-renal syndrome type 2}

% Authors list:
\author{WLUJ}{Janina Kowalska }
\author{CIL}{Zofia Dyrman}
\author{KCW}{Andrzej Jarzyna}
\author{CIL}{Wacław Jarząbek}
\author{CIL}{Krzysztof Chrostowicz}
% Undefined affiliation raises an error:
% \author{DoPX}{Zdzisław Dyrman}

% Affliations list:
\affiliation{WLUJ}{Wydział Lekarski Uniwersytetu Jagiellońskiego
-- Collegium Medicum, ul.~św.~Anny 12, 31--008 Kraków}
\affiliation{CIL}{Centrum Interwencyjnego Leczenia Chorób Serca
i~Naczyń, KSzS im.~Jana Pawła II, ul. Prądnicka 80, 31--202 Kraków}
\affiliation{KCW}{Klinika Choroby Wieńcowej UJ, Collegium Medicum,
KSzS im. Jana Pawła II, ul. Prądnicka 80, 31--202 Kraków}
% Extra affiliation raises an error:
% \affiliation{DRS}{Druskienniki, Pendological Department}

% Short versions of title/authors list (defined if title/authors list
% is too long to fit the headlines:
% \shortauthor{Tratata}
% \shorttitle{Fififif}
%
\begin{document}
\maketitle

\end{document}
LaTeX example titlepage
The titlepage

The main problem is long lists of authors and affiliations. There are more authors than affiliations so affiliations are labelled with consecutive numbers and each author is marked with appropriate label indicating his/her affiliation. It can be done manually of course but with the help of a few clever macros the numbers can be computed by LaTeX. This feature can be particularly helpful when for instance just before the (printing house) deadline a very important author (probably professor) insists his affiliation should be 1 not 4 (for example). All is needed to achieve this is to reorder \affiliation declarations.

The resulting document looks like shown in the picture.

The macros used:


%++Authors and affiliations
\newcount \authornumber
\newcount \affiliationnumber
\authornumber=0
\affiliationnumber = 0
%
\def\alttitle#1{\gdef\@alttitle{#1}}%
\def\shortalttitle#1{\gdef\@shortalttitle{#1}}

\def\author#1#2{%
\global\advance\authornumber\@ne
\authorAffiliationId{#1}% -- label --
\authorName{#2}% -- author's name --
}
%
\def\authorAffiliationId#1{%
\expandafter\def\csname theauthorid\number%
\authornumber\endcsname {#1}% --author's id--
%% label defined to check if affiliation exists:--
\expandafter\def\csname theaffid:#1\endcsname {#1}%
}
%
\def\authorName#1{%
\expandafter\def\csname theauthor\number%
\authornumber\endcsname{\ignorespaces#1\unskip}%
\expandafter\let\csname theauthoraffiliation\number%
\authornumber\endcsname\relax
}
%
\def\affiliation#1#2{%
\global\advance\affiliationnumber\@ne
\expandafter\def\csname theaffiliation \number%
\affiliationnumber \endcsname {\ignorespaces#2\unskip}%
\expandafter\edef\csname affid:#1\endcsname {\number\affiliationnumber}%
%% if defined in class CLS add error mesage:
%%\@ifundefined{theaffid:#1}{\ClassError{CLS}{**Affiliation undefined: `#1'}\@ehc}{}%
}
%
\def\@author{\@defaultauthorlist}
\def\@affiliation{\@defaultaffiliationlist}
%
\newcount\count@@
%
% Authors/affiliations lists
\def\@defaultauthorlist{%
\count@=\authornumber
\count@@=0
\begingroup
\loop
\ifnum\count@>0
\advance\count@@ by 1
\ignorespaces\csname theauthor\number%%
\count@@\endcsname %-- autor's name --
\edef\@TmP@Aff@Etykieta{\csname theauthorid\number\count@@ \endcsname}%
% --check if \@TmP@Aff@Etykieta exists: --
\@ifundefined{affid:\@TmP@Aff@Etykieta}%
%% if defined in class CLS add error mesage:
%%{\ClassError{CLS}{**Brak afiliacji dla \csname theauthor\number%
%%\count@@\endcsname}\@ehc}%
%% print out affiliation label (number):
{$^{\csname affid:\@TmP@Aff@Etykieta\endcsname}$}%
%--Every author but last is separated by a comma--:
\ifnum\count@=1\relax\else,\space\fi
\advance\count@ by -1
\repeat
\endgroup
}
% Short list of authors (w/o affiliations labels) for headlines.
% Simplified version of @defaultauthorlist:
\def\@defaultshortauthorlist{%
\count@=\authornumber
\count@@=0
\begingroup
\loop
\ifnum\count@>0
\advance\count@@ by 1
\ignorespaces\csname theauthor\number\count@@\endcsname
\ifnum\count@=1\relax\else,\space\fi
\advance\count@ by -1
\repeat
\endgroup
}
%
% Affilitions list:
\def\@defaultaffiliationlist{%
\count@=\affiliationnumber
\count@@=0
\begingroup
\loop
\ifnum\count@>0
\advance\count@@ by 1
$^{\the\count@@}$ %-- affiliation number
%-- print out the affiliation:
\ignorespaces\csname theaffiliation \number\count@@\endcsname
% ++Every affiliation but last is separated by a comma ++ :
\ifnum\count@=1\relax\else,\space\fi
% każda afiliacja od nowego wiersza:
\par
\advance\count@ by -1
\repeat
\endgroup
}
% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
% ++SIMPLIFIED titlepage (just to demonstrate macros defined):++
\renewcommand\maketitle{%
\begin{titlepage}%
\let\footnotesize\small
\let\footnoterule\relax
\let \footnote \thanks
% ++Title: ++
\parindent0pt
\rightskip0pt plus 4em \pretolerance10001
\leavevmode \noindent
{\Large \sffamily \bfseries
\@title\par
% ++ Optional alternative title:
\@ifundefined{@alttitle}{}{\vskip9pt%
\large \sffamily \bfseries \@alttitle \par} }
\vspace{5mm}
% ++Authors list:
{\rightskip 0pt plus6em%
\@author\par}
%
\vspace{30pt}
% ++Affiliations list
{\rightskip 0pt plus6em \@affiliation\par}
%
% ++Define content for running headers/footers:
\@ifundefined{@shortauthorlist}{\gdef\@shortauthorlist{\@defaultshortauthorlist}}{}%
\@ifundefined{@shorttitle}{\gdef\@shorttitle{\@title}}{}%
\@ifundefined{@shortalttitle}{\gdef\@shortalttitle{\@alttitle}}{}%
%
\thispagestyle{empty}
\end{titlepage}%
%
\setcounter{footnote}{0}%
\global\let\thanks\relax
\global\let\maketitle\relax
\global\let\@thanks\@empty
\global\let\title\relax
\global\let\author\relax
\global\let\date\relax
\global\let\and\relax
}%%//maketitle//

\def\shorttitle#1{\gdef\@shorttitle{#1}}
\def\shortauthorlist#1{\gdef\@shortauthorlist{#1}}
\let\shortauthor\shortauthorlist

Brak komentarzy:

Prześlij komentarz