
\documentclass[a4paper,12pt,oneside]{article}

\usepackage{xunicode}
\usepackage{xltxtra}
\defaultfontfeatures{Mapping=tex-text}
\usepackage{xspace}
\usepackage[english,frenchb]{babel}
\usepackage{vmargin}
%\usepackage{times}
\usepackage{lmodern}
\usepackage{url}
\usepackage{eso-pic}
\usepackage{fancyvrb}
\usepackage[table]{xcolor}
\usepackage{forloop}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usepackage{calc}

\usepackage[a4paper, xetex, colorlinks, breaklinks, linkcolor=blue]{hyperref}

%% Insertion d'images
\ifx\pdfoutput\undefined
  % we are running LaTeX, not pdflatex
  \usepackage{graphicx}
\else
  % we are running pdflatex, so convert .eps files to .pdf
  \usepackage[pdftex]{graphicx}
  \usepackage{epstopdf}
\fi

%% Paramètres de mise en page
\setpapersize{A4}
\setmarginsrb   {5mm} % left margin
                {5mm} % top margin
                {5mm} % right margin
                {5mm} % bottom margin
                {0mm} % head height
                {0mm} % head sep
                {0mm} % foot height
                {0mm} % foot skip
\addtolength{\abovecaptionskip}{-7mm}
\addtolength{\belowcaptionskip}{-7mm}
\marginparsep 0mm
\marginparwidth 0mm
\marginparpush 0mm
\oddsidemargin 5mm
\evensidemargin 0mm
\parskip 6pt

%\newcommand\email{\begingroup \urlstyle{rm}\Url}
%\newcommand\web{\begingroup \urlstyle{tt}\Url}

\newcommand{\nohyphens}{\hyphenpenalty=10000\exhyphenpenalty=10000\relax}

\graphicspath{{img/}}

\def\img#1#2{
  \begin{center}
    \includegraphics[#1]{#2}
  \end{center}
}
\newcommand{\imgenv}[3]{
  \begin{figure}[!htb]
    \begin{center}
      \includegraphics[#2]{#1}
    \end{center}

    \caption{\label{#1}\emph{#3}}
  \end{figure}
}

% page headers
\pagestyle{empty}

% document info
\title {\textbf{Feuille de personnage Starwars}}
\author {Marc Dequènes (Duck)}
\hypersetup{
  pdftitle={Feuille de personnage Starwars},
  pdfauthor={Marc Dequènes (Duck)}
}

% parameters
\newcommand\characteristicNameSize{50mm}
\newcommand\characteristicValSize{10mm}
\newcommand\attributeColor{\cellcolor[gray]{0.7}}
\newcommand\specialSkillColor{\cellcolor[gray]{0.9}}
\newcommand\standardSkillNumber{14}
\newcommand\smallSkillNumber{12}
\newcommand\sidebarSize{47mm}

% internal macros
\newcounter{skillCount}
\newcounter{skillLoop}
\newcommand\characteristicNameSpace{\underline{\hspace{\characteristicNameSize}}}
\newcommand\characteristicValSpace{\underline{\hspace{\characteristicValSize}}}
\newlength{\characteristicDualValSize}
\setlength{\characteristicDualValSize}{\characteristicValSize - \widthof{\textit{/}}}
\setlength{\characteristicDualValSize}{\characteristicDualValSize / 2}
\newcommand\characteristicDualValSpace{\underline{\hspace{\characteristicDualValSize}/\hspace{\characteristicDualValSize}}}
\newcommand\attribute[1]{\attributeColor\textbf{#1} & \attributeColor\characteristicValSpace \\}
\newcommand\skill[1]{%
  \stepcounter{skillCount}%
  #1 & \characteristicValSpace \\
}
\newcommand\specialSkill[1]{%
  \stepcounter{skillCount}%
  \specialSkillColor\textit{#1} & \specialSkillColor\characteristicValSpace \\
}
\newcommand\specialSkillDual[1]{%
  \stepcounter{skillCount}%
  \specialSkillColor\textit{#1} & \specialSkillColor\characteristicDualValSpace \\
}
\newcommand\skillSpace{\characteristicNameSpace & \characteristicValSpace \\}
\newcommand\characteristicBlockSkillNumber{}
\newenvironment{characteristicBlock}[2]%
 {%
   \renewcommand\characteristicBlockSkillNumber{#2}%
   \setcounter{skillCount}{0}%
   \begin{tabular}{ @{} l l }%
   \attribute{#1}%
 }{%
   % workaround because the forloop introduce an unwanted newline
   % (add the last skillSpace manually after the loop and increase skillCount
   %  to loop one less time)
   \stepcounter{skillCount}%
   \forloop{skillLoop}{\value{skillCount}}{\value{skillLoop} < \characteristicBlockSkillNumber}{\skillSpace}%
   \skillSpace
   \end{tabular}%
 }
\newcommand\circleSpace{%
\begin{tikzpicture}
  \draw [semithick,black] (0,0) circle (0.7);
\end{tikzpicture}%
}
\newcommand\circleSplitSpace{%
\begin{tikzpicture}
  \draw [semithick,black] (0,0) circle (0.7);
  \draw [semithick,black] (-0.7,0) -- (0.7,0);
\end{tikzpicture}%
}
\newcommand\checkbox{%
  \begin{tikzpicture}
    \node [draw, rectangle, minimum width=5mm, minimum height=5mm] {};
  \end{tikzpicture}%
}
\newcommand\alignImageAfterText[2]{%
  % approximate solution (using a save box does not solve anything,
  % as we should take the final formatting/wrapping into account)
  \footnotesize{#1} & \raisebox{-0.5\height+0.5ex}{#2} \\
}
\newcolumntype{V}{>{\centering\arraybackslash} m{.05\linewidth} }
\newcommand{\shortnl}{\\[-3mm]}
\newcounter{nlCount}
\newcommand{\multinl}[1]{%
  \setcounter{nlCount}{0}%
  % see above for explanation about the problem with forloop
  \forloop{nlCount}{1}{\value{nlCount} < #1}{\\}%
  \\
}


\begin{document}
%
% don't break long lines
\sloppy
% don't break words
\nohyphens
%
\begin{center}
\huge{\textbf{Star Wars}}
\end{center}
%
% main layout table
\begin{tabular}{ @{} l l l }
%
\midrule
%
\multicolumn{2}{ @{} l @{} }{%
\begin{tabular}{ l @{} }
Nom: \\
Description physique: \\
\\
Personnalité: \\
\\
Activités: \\
\\
\end{tabular}}
%
&
%
\begin{tabular}{ l }
Race: \\
\addlinespace
Sexe: \\
\addlinespace
Age: \\
\addlinespace
Taille: \\
\addlinespace
Poids: \\
\end{tabular}
%
\\
\bottomrule
% spacing
\\
%
% characteristics tables (left part)
\begin{tabular}{ l }
%
\begin{characteristicBlock}{DEXTERITÉ}{\standardSkillNumber}
 \specialSkill{Deplacement}
 \skill{Esquive}
 \skill{Parade Main Nue}
\end{characteristicBlock}
\\
%
% spacing
\\
\begin{characteristicBlock}{SAVOIR}{\smallSkillNumber}
 \skill{Volonté}
\end{characteristicBlock}
\\
%
% spacing
\\
\begin{characteristicBlock}{MECANIQUE}{\standardSkillNumber}
\end{characteristicBlock}
\\
% characteristics tables (left part)
\end{tabular}
%
&
%
% characteristics tables (right part)
\begin{tabular}{ l }
%
\begin{characteristicBlock}{PERCEPTION}{\standardSkillNumber}
 \specialSkill{Grade*}
 \skill{Commandement*}
 \skill{Discrétion}
 \skill{Dissimulation}
 \skill{Persuasion}
 \skill{Recherche}
\end{characteristicBlock}
\\
%
% spacing
\\
\begin{characteristicBlock}{VIGUEUR}{\smallSkillNumber}
 \specialSkillDual{Protection (phy/en)}
 \skill{Combat à Main Nue}
 \skill{Escalade / Saut}
 \skill{Levage}
 \skill{Résistance}
\end{characteristicBlock}
\\
%
% spacing
\\
\begin{characteristicBlock}{TECHNIQUE}{\standardSkillNumber}
\end{characteristicBlock}
\\
% characteristics tables (right part)
\end{tabular}
%
&
%
%sidebar
\begin{tabular}{ @{} | c @{} }
%
\attributeColor\textbf{Portrait} \\
\shortnl
\begin{tikzpicture}
  \node [draw, rectangle, minimum width=40mm, minimum height=50mm] {};
\end{tikzpicture}
\\
\specialSkillColor Citation Typique \\
\underline{\hspace{40mm}} \\
\underline{\hspace{40mm}} \\
\underline{\hspace{40mm}} \\
\shortnl
\attributeColor\textbf{Blessures} \\
\shortnl
\begin{tabular}{ @{} c c @{} }
  \alignImageAfterText{Sonné}{\checkbox\checkbox}
\end{tabular}
\\
\shortnl
\begin{tabular}{ @{} c c c c @{} }
  B & SB & N & MB \\
  \checkbox & \checkbox & \checkbox & \checkbox \\
\end{tabular}
\\
\begin{tabularx}{\sidebarSize}{ @{} X l @{} }
  \alignImageAfterText{Fatigue act/max :}{\circleSplitSpace}
\end{tabularx}
\\
\shortnl
\attributeColor\textbf{Actions Hâtives} \\
\shortnl
\begin{tikzpicture}
  \node [draw, rectangle, rectangle split, rectangle split horizontal,
         rectangle split parts=3, rectangle split empty part width=10mm,
         minimum height=8mm] {};
\end{tikzpicture}
\\
\shortnl
\attributeColor\textbf{La Force} \\
%
\begin{tabularx}{\sidebarSize}{ @{} X l @{} }
  \specialSkillColor Contrôle* & \specialSkillColor\characteristicValSpace \\
  \specialSkillColor Sens* & \specialSkillColor\characteristicValSpace \\
  \specialSkillColor Alteration* & \specialSkillColor\characteristicValSpace \\
\end{tabularx} \\
\shortnl
\begin{tabularx}{\sidebarSize}{ @{} X l @{} }
  \alignImageAfterText{Force}{\circleSpace}
  \addlinespace
  \alignImageAfterText{Côté Obscur act/tot}{\circleSplitSpace}
\end{tabularx}
\\
\shortnl
\attributeColor\textbf{Expérience} \\
\shortnl
\begin{tabularx}{\sidebarSize}{ @{} X l @{} }
  \alignImageAfterText{PC dispo/tot :}{\circleSplitSpace}
\end{tabularx}
\\
% silly padding
\\[15pt]
% sidebar
\end{tabular}
\\
%
% main layout table
\end{tabular}
%
\pagebreak
%
% main layout table
\begin{tabular}{ @{} | l | }
%
\hline
\begin{tabularx}{\textwidth-7mm}{ @{} X | X @{} }
  \attributeColor\textbf{Talents spéciaux} & \attributeColor\textbf{Relation avec les Autres Personnages} \\
  \multinl{12} \\
\end{tabularx}
\\
\hline
\attributeColor\textbf{Équipement} \\
\multinl{20}
\hline
\attributeColor\textbf{Notes} \\
\multinl{20}
\hline
%
% main layout table
\end{tabular}
%
\end{document}
