I need to create a wide table, like the example below, that will span the whole pdf page after it's rendered in latex.
The problem I'm having is that the column header text is not wrapping to fit the width of the column.
+----------+--------------------------------+------------------------+----------+----------+----------+----------+----------+
| Header 1 | Long Header 2 that should wrap | Common column Header 3 | Header 4 | Header 5 | Header 6 | Header 7 | Header 8 |
| | +-----------+------------+ | | | | |
| | | Header 3a | Header 3b | | | | | |
+==========+================================+===========+============+==========+==========+==========+==========+==========+
| Value 1 | Value 2 does actually wrap | Value 3a | Value 3b | Value 4 | Value 5 | Value 6 | Value 7 | Value 8 |
+----------+--------------------------------+-----------+------------+----------+----------+----------+----------+----------+
Shows up like this:
I've tried adjusting column widths using the .. tabularcolumns:: |p{0.1 \textwidth|...
directive, but it didn't seem to fix the encroaching header text problem.
If I remove the "Common column Header 3" (second example below) I get the desired wrapping header text behavior, so I'm guessing I'm doing something wrong with that part:
+----------+--------------------------------+-----------+------------+----------+----------+----------+----------+----------+
| Header 1 | Long Header 2 that should wrap | Header 3a | Header 3b | Header 4 | Header 5 | Header 6 | Header 7 | Header 8 |
| | | | | | | | | |
| | | | | | | | | |
+==========+================================+===========+============+==========+==========+==========+==========+==========+
| Value 1 | Value 2 does actually wrap | Value 3a | Value 3b | Value 4 | Value 5 | Value 6 | Value 7 | Value 8 |
+----------+--------------------------------+-----------+------------+----------+----------+----------+----------+----------+
Looks like this:
Any help would be greatly appreciated!
You can add reStructured Text table syntax with .. list-table:: directive. Each table has the number of columns and their associated relative widths indicated in a width tag. For proper formatting, the asterisk indicating each row must align vertically, and the hyphens indicating each column must also align.
The tabular environment is the default LaTeX method to create tables. You must specify a parameter to this environment, {c c c} tells LaTeX that there will be three columns and that the text inside each one of them must be centred. Open an example in Overleaf.
It’s often easier to create tables in a program like Excel than with RST syntax. You can then save the table as a CSV file, and reference the CSV file in your reStructured Text file where you want the table to go.
In general, you may want to use the command \multicolumn{4}{c}{\bfseries Table header line}}to typeset the header line of a tabularenvironment that has four columns; "Table header line" would need to be replaced by the actual header you have in mind.
It's not a perfect solution, but you should be able to manually force the text to the next line with the newline character |
(pipe and 2 spaces) like so:
+---------------------------
| | Header | | Header |
| | 1 | | 2 |
+==============+===========+
| value 1 | value 2 |
+--------------+-----------+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With