Skip to content

Add option to specify table env. in LaTeX output #4392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pajowu
Copy link

@pajowu pajowu commented Feb 22, 2018

This PR adds a command line switch (--latex-table-environment) for switching between possible table environments. Currently pandoc is hardcoded to use longtable, which allows for multi-page-tables. This adds support for the tabularx environment (allowing columns that span over the while remaining table-width) and gives the possibility to easily add new environments in the future.

NOTE: The package used in the template could also be ltablex, which is a combination of longtable and tabularx (allows multi-page tables with auto-spanning columns).

@pajowu
Copy link
Author

pajowu commented Apr 5, 2018

Is there something blocking this PR?

MANUAL.txt Outdated
`--latex-table-environment=longtable`|`tabularx`

: Use the specified table environment when producing LaTeX output.
The default is [`longtable`] which allows table to spread over multiple tables.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean "over multiple pages"?

MANUAL.txt Outdated

: Use the specified table environment when producing LaTeX output.
The default is [`longtable`] which allows table to spread over multiple tables.
[`tabularx`] allows for columns which autospread over the entire linewidth.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure exactly what was meant by "autospread over the entire linewidth."

Copy link
Contributor

@agusmba agusmba Oct 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe taking from the description of the ctan package:
" [tabularx] allows for paragraph-like columns whose width automatically expand to fill the width of the environment"

@jgm
Copy link
Owner

jgm commented Apr 5, 2018

Sorry, I just haven't had time to review it. Can you say more about the motivation for the change?

@themightyoarfish
Copy link

One motivation from my perspective is that longtable is broken in the presence of floats on the same page (see e.g.here or here)

In my case, this happily pushes sections into the bottom margin and the space between pages, so they are lost.

This is a known bug in longtable, but unfortunately it also breaks pandoc use in cases, so an option for this would be great.

@themightyoarfish
Copy link

Could this be moved along? I don't have a workaround for this right now.

@pajowu pajowu force-pushed the ken/latex-table-environment branch from 2941904 to 01b9275 Compare November 9, 2018 10:11
This commit adds a command line switch (`--latex-table-environment`) for
switching between possible table environments. Currently pandoc is
hardcoded to use `longtable`, which allows for multi-page-tables. This
commit adds support for the tabularx environment (allowing columns that
span over the while remaining table-width) and gives the possibility to
easily add new environments in the future.
@pajowu pajowu force-pushed the ken/latex-table-environment branch from 01b9275 to f16e43e Compare November 9, 2018 11:16
@pajowu
Copy link
Author

pajowu commented Nov 9, 2018

I updated the documentation according to your Remarks and fixed all merge conflicts. The PR should be mergable again

Regarding my motivation: longtable inserts empty pages or overflows the page when float objects are on the same page. This makes longtable unusable for us. Longtable also does not have an option to say that one column should fill the rest of the linewidth, which we also need. With this patch applied and ltablex used as the table class, both issues are fixed


: Use the specified table environment when producing LaTeX output.
The default is [`longtable`] which allows table to spread over multiple pages.
[`tabularx`] allows for paragraph-like columns whose width automatically expand to fill the width of the environment.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines should be hard-wrapped to fit within 80 columns.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I quite understand this description: "paragraph-like columns whose width automatically expand to fill the width of the environment." Maybe better to say something about what should dictate this choice? For example: If you have long tables that may need to spans multiple pages, use longtable. If you want to create floating tables (and for better compatibility with other floating elements on the page), use tabularx.

@@ -1599,6 +1607,10 @@ LaTeX variables are used when [creating a PDF].
supports 'plain' (default), 'empty', and 'headings'; headings puts
section titles in the header.

`table_environment`
: The environemnt given by `--latex-table-environment`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"environment"

@@ -850,6 +850,17 @@ options =
UTF8.hPutStr stdout (usageMessage prg options)
exitSuccess ))
"" -- "Show help"
, Option "" ["latex-table-class"]
Copy link
Owner

@jgm jgm Nov 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be latex-table-environment, given the documentation? (also elsewhere)

@@ -168,6 +169,11 @@ data ReferenceLocation = EndOfBlock -- ^ End of block
| EndOfDocument -- ^ at end of document
deriving (Show, Read, Eq, Data, Typeable, Generic)

-- | Class of tables to use in LaTeX output
data LatexTableEnvironment = Longtable -- ^ Use longtable for tables
| Tabularx -- ^ Use tabularx tables
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should align as in the other examples in the code.

@@ -204,7 +210,8 @@ data WriterOptions = WriterOptions
, writerReferenceLocation :: ReferenceLocation -- ^ Location of footnotes and references for writing markdown
, writerSyntaxMap :: SyntaxMap
, writerPreferAscii :: Bool -- ^ Prefer ASCII representations of characters when possible
} deriving (Show, Data, Typeable, Generic)
, writerLatexTableEnvironment :: LatexTableEnvironment
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note clearly the API change in the commit comment.

case align of
AlignLeft -> "l"
AlignRight -> "r"
AlignCenter -> "c"
AlignDefault -> "l"
AlignDefault -> if index == 0 then "l" else "X"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is "l" used for the first column and then "X"?

@jgm
Copy link
Owner

jgm commented Nov 9, 2018

Thanks for the update. I've made some comments to your patch.

Currently there are no tests. There should be tests.

Also, your patch assumes that the only differences between the environments lie in the column specs and environment name. Have you tested things like captions, footnotes in table cells, and so on, to make sure that this is the case?

@randrej
Copy link

randrej commented Jan 20, 2019

Wouldn't it make sense to use tabu instead of
tabularx?

tabu's environment longtabu mimics the longtable environment that it can
span multiple pages, but it allows for using x columns (columns with width
expanded so that the table takes up the whole \textwidth). It can also be used
just to stretch the table to full width by widening every column equally, just
like tabularx.

tabu also painlessly mends many of the concerns expressed here:

Also, your patch assumes that the only differences between the environments
lie in the column specs and environment name. Have you tested things like
captions, footnotes in table cells, and so on, to make sure that this is the
case?

Tabu is very much compatible with longtable as far as the table contents go.
While tabularx doesn't allow footnotes and verbatim text, tabu does. It can
also contain other tabu, tabular*, tabularx environments.

Like tabularx, tabu allows for specifying which columns are stretched in
the final output. Pandoc markdown currently doesn't have any way of specifying
that a column should be stretched, though. tabu can be used without
specifying which column to stretch. This stretches all of the columns.
Implementing this wouldn't require any changes to Pandoc markdown syntax.

New syntax spitballing

If you wanted to add syntax for column stretching, I have some suggestions.

I guess a solution that relies on the number of leading or trailing dashes is
out of question, since it could break someone's overly inset tables.

Hence, adding another character to the ---- lines to designate that the line
stretches seems like the simplest solution. I'll use the * character in my
examples, but it could be any character. A tilde ~ may be a nice choice, it's
visually similar to a dash. Adding a new character makes this effortlessly
backwards compatible.

Style 1:

* is placed on the side that specifies the alignment, and on both sides for
central alignment.

 def. aligned reg.  RA reg. str. LA   str. RA  str. CA  reg. LA
 ----------------- -------- -------* *------- *-------* ----------
 1                        2 3               4        5  6
 7                        8 9              10       11  12

Style 2:

* is always placed on the right side and is treated as a regular - for
alignment purposes

 def. aligned reg.  RA reg. str. LA   str. RA  str. CA  reg. LA
 ----------------- -------- -------* -------* --------* ----------
 1                        2 3               4        5  6
 7                        8 9              10       11  12

Similar syntax could be used for other types of tables. I could try to think
something up if you like this.

New syntax or no, tabu looks like a promising replacement for longtable. We
could add a global --latex-use-longtable option to ignore this syntax and
retain the things the way they currently are.

I believe that this extension to the syntax would bring value to users
(especially those who write scientific papers and anything else for
publishing). A writer could be easily written for HTML-based formats, too.

@jgm
Copy link
Owner

jgm commented Jan 22, 2019 via email

@Grandement
Copy link

I would prefer longtabu as well instead of longtable. The definition of longtabu is close to longtable and I guess it is not a big deal to add it with a optional argument to pandoc. The tabu packge is still working well :). With longtabu automatic linebreaks in a cell are possible due to the column X definition which would be a benifit for pandoc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants