Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a large table in rst with nested column headers and getting the latex rendering to wrap the header text

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:

Header 2 encroaches into 3rd column

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:

Desired text wrapping behavior for Header 2

Any help would be greatly appreciated!

like image 441
AlexP21 Avatar asked Dec 13 '16 22:12

AlexP21


People also ask

How to add ReStructured Text TABLE syntax?

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.

How do I create a table in latex?

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.

How do I create a table in Excel instead of RST?

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.

How do I create a table header line with 4 columns?

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.


1 Answers

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   |
+--------------+-----------+
like image 177
Kyle Avatar answered Sep 18 '22 13:09

Kyle