4 - Tableaux 1 L`environnement tabular

Transcription

4 - Tableaux 1 L`environnement tabular
4 - Tableaux
Formation LATEX
1
2011
L’environnement tabular
L’environnement tabular permet de réaliser des tableaux avec ou sans lignes de séparation horizontales ou
verticales. LATEX ajuste automatiquement la largeur des colonnes.
L’argument description du tableau de la commande : \begin{tabular}{description du tableau} définit le format
des colonnes du tableau. Utilisez un l (left) pour une colonne alignée à gauche, r(right) pour une colonne alignée à
droite et c (center) pour une colonne centrée. p{largeur} permet de réaliser une colonne justifiée à droite sur plusieurs
lignes et enfin | permet d’obtenir une ligne verticale.
1. Un tableau basique.
Tableau 1 :
x
f(x)
-1
-0,6
-0,2
0,2
0,6
1
Code du tableau 1 :
\begin{tabular}{|c||l|l|l|l|l|l|} \hline
x
& -1 & -0,6 & -0,2 & 0,2 & 0,6 & 1 \\ \hline
f(x) &
&
&
&
&
&
\\ \hline \end{tabular}
2. Si l’on veut des colonnes plus larges, il faut définir leur largeur.
Tableau
x
f(x)
-1
-0,6
-0,2
0,2
0,6
1
Code du tableau
\begin{tabular}{|c||p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|} \hline
x
& -1 & -0,6 & -0,2 & 0,2 & 0,6 & 1 \\ \hline
f(x) &
&
&
&
&
&
\\ \hline \end{tabular}
3. L’environnement tabularx permet d’obtenir un tableau ayant une largeur prédéfinie dont toutes les colonnes
ont la même largeur.
Tableau
x
f(x)
-1
-0,6
-0,2
0,2
0,6
1
Code du tableau
\begin{tabularx}{0.8\linewidth}{|c||*{6}{>{\centering \arraybackslash}X|}}\hline
x
& -1 & -0,6 & -0,2 & 0,2 & 0,6 & 1 \\ \hline
f(x) &
&
&
&
&
&
\\ \hline \end{tabularx}
Remarques :
a. La largeur du tableau est définie en fonction de la largeur totale de la ligne. 0.8\linewidth
b. La première colonne est ajustée automatiquement en fonction du contenu des élements de cette colonne.
c. Les autres éléments sont centrés ( Pour aligner à gauche, remplacer \centering par \flushleft, Pour
aligner à gauche, remplacer \centering par \flushright).
4. Il est possible d’augmenter la hauteur des lignes avec la commande : \renewcommand{\arraystretch}{2}
Tableau
x
-1
-0,6
-0,2
0,2
f(x)
Code du tableau
\renewcommand{\arraystretch}{2}
\begin{tabularx}{0.8\linewidth}{|c||*{6}{>{\centering \arraybackslash}X|}}\hline
x
& -1 & -0,6 & -0,2 & 0,2 & 0,6 & 1 \\ \hline
f(x) &
&
&
&
&
&
\\ \hline \end{tabularx}
http://bernard.gault.free.fr
1
0,6
1
4 - Tableaux
Formation LATEX
2011
5. On peut aussi augmenter la hauteur des lignes en augmentant la hauteur des lignes de plusieurs points avec la
commande \setlength{\extrarowheight}{6pt} à placer dans le préambule.
tableau
x
-10
-6
-4
-2
0
f (x)
0
-16
-20
-21,333
-20
code du tableau
\begin{tabular}{|c||*{5}{c|}} \hline
\makebox[1.5cm][c]{$x$} & \makebox[1.5cm][c]{-10}
& \makebox[1.5cm][c]{-6} & \makebox[1.5cm][c]{-4}
& \makebox[1.5cm][c]{-2} & \makebox[1.5cm][c]{0}\\ \hline
\makebox[1.5cm][c]{$f(x)$} & 0 & -16 & -20 & -21,333
\end{tabular}
&
-20 \\ \hline
Remarquer l’utilisation des boı̂tes pour définir la taille des colonnes.
6. On peut faire un tableau de tableaux
tableau
(d1 ) : y =
4
x+6
3
x
−6
0
y
−2
0
(d2 ) : y =
3
06016016
d
-1.49.96264Tf .28236(3)-264Tf66264Tf6.84023Td32(1)1.60599]TJ /R149.7264TTf 11.640+0Td [(=)-5.14816]TJ 11.64026.71892Td [(3)-
4 - Tableaux
Formation LATEX
2
2011
L’environnement array
Doit-être appelé dans l’en-tête du document : \usepackage{array}
L’environnement array fonctionne de manière similaire à l’environnement tabular mais Il est placé un environnement
mathématique. Il faudra donc prendre des précautions pour insérer des élements de texte.
Tableau 1 :
-1
x
f (x)
-0,6
-0,2
0,2
0,6
1
Code du tableau 1 :
$ \begin{array}{|c||p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|}\hhline{-||------}
x
& -1 & -0,6 & -0,2 & 0,2 & 0,6 & 1 \\ \hhline{-||------}
f(x) &
&
&
&
&
&
\\ \hhline{-||------}
\end{array}$
Tableau 2 :
Valeurs de x
f (x)
-1
-0,6
-0,2
0,2
0,6
1
Code du tableau 2 :
$\begin{array}{|c||p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|p{1.5cm}|}\hhline{-||------}
\text{Valeurs de } x
& -1 & -0,6 & -0,2 & 0,2 & 0,6 & 1 \\ \hhline{-||------}
f(x) &
&
&
&
&
&
\\ \hhline{-||------}
\end{array}$
Tableau 3 :
Formule n°1
Formule n°2
Formule n°3
Abonnement mensuel
fixe pour deux heures
de communications
Supplément par minute
commencée au delà de
deux heures
30 €
10 €
17 €
0,25 €
0,75 €
0,50 €
Code du tableau 3 :
\begin{tabular}{|c||*{2}{c|}} \hline
\makebox[3cm][c]{˜} & \parbox[][1.5cm][c]{3.7cm}{Abonnement mensuel fixe pour deux heures de communications}
& \parbox[][1.5cm][c]{4cm}{Supplément par minute commencée au delà de deux heures}\\ \hline
\makebox[3cm][c]{Formule n°1} & \makebox[1.5cm][c]{30 \euro} & \makebox[1.5cm][c]{0,25 \euro}\\ \hline
\makebox[3cm][c]{Formule n°2} & \makebox[1.5cm][c]{10 \euro} & \makebox[1.5cm][c]{0,75 \euro}\\ \hline
\makebox[3cm][c]{Formule n°3} & \makebox[1.5cm][c]{17 \euro} & \makebox[1.5cm][c]{0,50 \euro}\\ \hline
\end{tabular}
http://bernard.gault.free.fr
3
4 - Tableaux
Formation LATEX
3
2011
D’autres exemples pour s’amuser
A. Einstein
M. Curie
A
nn
é
N
ob
el
\renewcommand{\arraystretch}{1.8}
\setlength{\tabcolsep}{3mm}
\begin{tabular}%
{|>{\large\bfseries}l|c|c|}
\cline{2-3}
\multicolumn{1}{c|}{} &
\rotatebox{45}{Nobel} &
\rotatebox{45}{Année }\\ \hline
A. Einstein & Physique & 1905 \\ \hline
\multirow{2}*{M. Curie} & Physique & 1903 \\
\cline{2-3}
& Chimie & 1911 \\ \hline
\end{tabular}
e
Autre exemple : qui necéssite le package multirow et le package graphics
Physique
1905
Physique
1903
Chimie
1911
Un jeu de sudoku :
\newcolumntype{I}{!{\vrule width 1.5pt}}
\newlength\savedwidth
\newcommand\whline{\noalign{\global\savedwidth
\arrayrulewidth\global\arrayrulewidth 1.5pt}
\hline \noalign{\global\arrayrulewidth
\savedwidth}
}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{Ic|c|cIc|c|cIc|c|cI}
\whline
1 & 6 & 4 &
&
&
&
&
& 2 \\
2 &
&
& 4 & 6 & 3 & 9 & 1 &
\\
&
& 5 &
& 8 &
& 4 &
& 7 \\
& 9 &
&
&
& 6 & 5 &
&
\\
5 &
&
& 1 &
& 2 &
&
& 8 \\
&
& 8 & 9 &
&
&
& 3 &
\\
8 &
& 9 &
& 4 &
& 2 &
&
\\
& 7 & 3 & 5 &
& 9 &
&
& 1 \\
4 &
&
&
&
&
& 6 & 7 & 9 \\
\end{tabular}
http://bernard.gault.free.fr
1
6
4
2
2
4
5
6
8
9
1
8
8
4
4
3
7
2
8
3
4
5
1
5
9
9
7
9
4
6
5
\hline
\hline
\whline
\hline
\hline
\whline
\hline
\hline
\whline
3
2
9
1
6
7
9