Ceci est une ancienne révision du document !

— title: Variable-width columns in tables category: floats tags:

  1. tables
  2. figures

permalink: /FAQ-varwidcol —

This is a slightly different take on the problem addressed in “[fixed-width tables](FAQ-fixwidtab)” — 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) and [`ltxtable`](https://ctan.org/pkg/ltxtable) packages) are the same for this problem as for the fixed-width _table_ problem, there's one extra tool that we can call to our aid, which may be preferable in some situations.

Suppose we have data in one column which we read from an external source, and the source itself isn't entirely predictable. The data in the column may end up pretty narrow in every row of the table, or it may be wide enough that the table would run over the edge of the page; 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 “[automatic sizing of minipages](FAQ-varwidth)”, provides a solution. If you load it together with the LaTeX “required” [`array`](https://ctan.org/pkg/array) package, i.e.: ```latex \usepackage{array} \usepackage{varwidth} ``` [`varwidth`](https://ctan.org/pkg/varwidth) defines a new column-type `V`, which you can use as follows: ```latex \begin{tabular}{l V{3.5cm} r}

foo & blah      & bar \\
foo & blah blah & bar \\

\end{tabular} ``` when the second column ends up less than 3.5cm wide; or you can use it as follows: ```latex \begin{tabular}{l V{3.5cm} r}

foo & blah      & bar \\
foo & blah blah & bar \\
foo & blah blah blah blah blah blah
                & bar \\

\end{tabular} ``` where the second column will end up noticeably wider, and will wrap to a second line in the third row.

3_composition/tableaux/colonnes/faire_varier_la_largeur_de_colonnes.1528032916.txt.gz · Dernière modification: 2018/06/03 15:35 par d.p.carlisle
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0