Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente Dernière révision Les deux révisions suivantes | ||
3_composition:tableaux:colonnes:faire_varier_la_largeur_de_colonnes [2018/05/23 18:48] joseph.wright |
3_composition:tableaux:colonnes:faire_varier_la_largeur_de_colonnes [2021/05/24 21:20] jejust Traduction en français. Compilation des exemples. |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | --- | + | ====== Comment avoir des colonnes de largeur variable dans un tableau? ====== |
- | ID: Q-varwidcol | + | |
- | revised: 2014-06-10 | + | |
- | --- | + | |
- | # Variable-width columns in tables | + | |
- | This is a slightly different take on the problem addressed in | ||
- | ''[fixed-width tables](FAQ-fixwidtab.md)'' — here we have | ||
- | a column whose size we can't absolutely predict when we design the | ||
- | document. | ||
- | While the basic techniques (the [`tabularx`](https://ctan.org/pkg/tabularx), [`tabulary`](https://ctan.org/pkg/tabulary) | + | Il s'agit d'une version légèrement différente du problème abordé dans |
- | and [`ltxtable`](https://ctan.org/pkg/ltxtable) packages) are the same for this problem as for the | + | « [[3_composition/tableaux/fixer_la_largeur_d_un_tableau|Comment fixer la largeur d'un tableau?]] ». |
- | fixed-width _table_ problem, there's one extra tool that we can | + | Ici, nous avons une colonne dont nous ne pouvons pas prévoir la taille |
- | call to our aid, which may be preferable in some situations. | + | au moment de l'écriture du document. |
- | Suppose we have data in one column which we read from an external | + | Si les techniques de base sont les mêmes pour ce problème que pour celui des tableaux à largeur déterminée, |
- | source, and the source itself isn't entirely predictable. The data in | + | avec les extensions [[ctanpkg>tabularx]], [[ctanpkg>tabulary]] et [[ctanpkg>ltxtable]], |
- | the column may end up pretty narrow in every row of the table, or it | + | il existe un outil supplémentaire que nous pouvons appeler à notre secours et est préférable |
- | may be wide enough that the table would run over the edge of the page; | + | dans certaines situations. |
- | however, we don't want to make the column as wide as possible ''just | + | |
- | in case'', by defining a fixed size for the table. We would like the | + | |
- | column to be as small as possible, but have the possibility to spread | + | |
- | to a maximum width and (if even that width is exceeded) turn into a | + | |
- | `p`-style column. | + | |
- | The [`varwidth`](https://ctan.org/pkg/varwidth) package, discussed in | + | Supposons que le contenu d'une colonne soit lu à partir d'une source externe, |
- | ''[automatic sizing of minipages](FAQ-varwidth.md)'', provides | + | et que la source elle-même ne soit pas entièrement prévisible. Ce contenu |
- | a solution. If you load it together with the LaTeX ''required'' | + | est parfois étroit, mais d'autres fois tellement large que le tableau déborde de la page; |
- | [`array`](https://ctan.org/pkg/array) package, i.e.: | + | cependant, nous ne voulons pas rendre la colonne aussi large que possible « juste au cas où », |
- | ```latex | + | en donnant une taille fixe au tableau. Nous aimerions que la colonne soit aussi petite que possible, |
- | \usepackage{array} | + | mais qu'elle ait la possibilité de s'étendre jusqu'à une largeur maximale et, si cette largeur |
- | \usepackage{varwidth} | + | en question est dépassée, de se transformer en une colonne de style ''p'' pour que son contenu |
- | ``` | + | se répartisse sur plusieurs lignes. |
- | [`varwidth`](https://ctan.org/pkg/varwidth) defines a new column-type `V`, which you | + | |
- | can use as follows: | + | The [[ctanpkg>varwidth]] package, discussed in |
- | ```latex | + | "[[FAQ-varwidth|automatic sizing of minipages]]", provides |
+ | a solution. If you load it together with the LaTeX "required" | ||
+ | [[ctanpkg>array]] package, i.e.: | ||
+ | |||
+ | L'extension [[ctanpkg>varwidth]], dont il a été question dans | ||
+ | « [[3_composition:texte:paragraphes:ajuster_la_taille_d_une_minipage|Comment optimiser la largeur d'une minipage?]] », | ||
+ | offre une solution. Si vous la chargez en même temps que l'incontournable extension [[ctanpkg>array]], | ||
+ | elle définira un nouveau type de colonne, ''V'', que vous pouvez utiliser comme ceci: | ||
+ | |||
+ | <WRAP column 50ex> | ||
+ | <code latex> | ||
+ | \documentclass{article} | ||
+ | \usepackage{array} | ||
+ | \usepackage{varwidth} | ||
+ | |||
+ | \begin{document} | ||
\begin{tabular}{l V{3.5cm} r} | \begin{tabular}{l V{3.5cm} r} | ||
foo & blah & bar \\ | foo & blah & bar \\ | ||
foo & blah blah & bar \\ | foo & blah blah & bar \\ | ||
\end{tabular} | \end{tabular} | ||
- | ``` | + | \end{document} |
- | when the second column ends up less than 3.5cm wide; | + | </code> |
- | or you can use it as follows: | + | </WRAP> |
- | ```latex | + | <WRAP column 30ex> |
+ | <latexdoc> | ||
+ | \documentclass{article} | ||
+ | \usepackage{array} | ||
+ | \usepackage{varwidth} | ||
+ | \pagestyle{empty} | ||
+ | |||
+ | \begin{document} | ||
+ | \begin{tabular}{l V{3.5cm} r} | ||
+ | foo & blah & bar \\ | ||
+ | foo & blah blah & bar \\ | ||
+ | \end{tabular} | ||
+ | \end{document} | ||
+ | </latexdoc> | ||
+ | </WRAP> | ||
+ | <WRAP clear/> | ||
+ | |||
+ | Dans l'exemple précédent, la colonne centrale avait une largeur inférieure à 3,5(nbsp)cm. | ||
+ | Voyons ce qui se passe quand son contenu s'étend: | ||
+ | |||
+ | <WRAP column 50ex> | ||
+ | <code latex> | ||
+ | \documentclass{article} | ||
+ | \usepackage{array} | ||
+ | \usepackage{varwidth} | ||
+ | |||
+ | \begin{document} | ||
\begin{tabular}{l V{3.5cm} r} | \begin{tabular}{l V{3.5cm} r} | ||
foo & blah & bar \\ | foo & blah & bar \\ | ||
Ligne 50: | Ligne 78: | ||
& bar \\ | & bar \\ | ||
\end{tabular} | \end{tabular} | ||
- | ``` | + | \end{document} |
+ | </code> | ||
+ | </WRAP> | ||
+ | <WRAP column 30ex> | ||
+ | <latexdoc> | ||
+ | \documentclass{article} | ||
+ | \usepackage{array} | ||
+ | \usepackage{varwidth} | ||
+ | \pagestyle{empty} | ||
+ | |||
+ | \begin{document} | ||
+ | \begin{tabular}{l V{3.5cm} r} | ||
+ | foo & blah & bar \\ | ||
+ | foo & blah blah & bar \\ | ||
+ | foo & blah blah blah blah blah blah | ||
+ | & bar \\ | ||
+ | \end{tabular} | ||
+ | \end{document} | ||
+ | </latexdoc> | ||
+ | </WRAP> | ||
+ | <WRAP clear/> | ||
+ | |||
where the second column will end up noticeably wider, and will wrap to | where the second column will end up noticeably wider, and will wrap to | ||
a second line in the third row. | a second line in the third row. | ||
+ | où la deuxième colonne sera sensiblement plus large, et s'enroulera sur une deuxième ligne dans la troisième rangée. | ||
+ | |||
+ | |||
+ | ----- | ||
+ | //Source:// [[faquk>FAQ-varwidcol|Variable-width columns in tables]] | ||
+ | |||
+ | {{htmlmetatags>metatag-keywords=(LaTeX,flottants,table,tableau,mise en forme des tableaux) | ||
+ | metatag-og:title=(Avoir des colonnes de largeur variable dans un tableau) | ||
+ | metatag-og:site_name=(FAQ LaTeX francophone) | ||
+ | }} | ||