Skip to content
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

Table rows are too wide. #29

Open
Wandmalfarbe opened this issue Feb 28, 2018 · 5 comments
Open

Table rows are too wide. #29

Wandmalfarbe opened this issue Feb 28, 2018 · 5 comments

Comments

@Wandmalfarbe
Copy link
Owner

screen shot 2018-02-28 at 22 05 37

See also jgm/pandoc#3929

A current workaround is to embed raw latex tables in the markdown document.

@gillesB
Copy link

gillesB commented Mar 5, 2018

Hello,
have you considered lua-filters as a workaround for this issue?
With these filters it is possible to replace the Pandoc AST Table blocks with another AST block.
For example with some raw LaTeX block.

As I have a hard time reading Haskell, I only created the following proof-of-concept to ask you about your opinion.

When the following lua-filter is applied, all tables get replaced by the hardcoded table from the filter.

function Table(table)
	return pandoc.RawBlock('tex', hardCodedTable(table))
end

function hardCodedTable(alignment)
	rawLatex = "\\begin{longtable}[]{rllc}\n" ..
	"\\caption{Some hardcoded table}\\tabularnewline\n" ..
	"\\toprule\n" ..
	"\\textbf{Right} & Left & Default & Center\\tabularnewline\n" ..
	"\\midrule\n" ..
	"\\endfirsthead\n" ..
	"\\toprule\n" ..
	"\\textbf{Right} & Left & Default & Center\\tabularnewline\n" ..
	"\\midrule\n" ..
	"\\endhead\n" ..
	"4711 & 12 & 12 & 12\\tabularnewline\n" ..
	"4711 & 123 & 123 & 123\\tabularnewline\n" ..
	"4711 & 1 & 1 & 1\\tabularnewline\n" ..
	"\\bottomrule\n" ..
	"\\end{longtable}\n"
	return rawLatex
end

Therefore the following Markdown file, results in the following LaTeX file.

# Header 1

| **Right** | Left | Default | Center |
|------:|:-----|---------|:------:|
|   12  |  12  |    12   |    12  |
|  123  |  123 |   123   |   123  |
|    1  |    1 |     1   |     1  |
: Table 1

| **Right** | Left | Default | Center |
|------:|:-----|---------|:------:|
|   12  |  12  |    12   |    12  |
|  123  |  123 |   123   |   123  |
|    1  |    1 |     1   |     1  |
: Table 2
\hypertarget{header-1}{%
\section{Header 1}\label{header-1}}

\begin{longtable}[]{rllc}
\caption{Some hardcoded table}\tabularnewline
\toprule
\textbf{Right} & Left & Default & Center\tabularnewline
\midrule
\endfirsthead
\toprule
\textbf{Right} & Left & Default & Center\tabularnewline
\midrule
\endhead
4711 & 12 & 12 & 12\tabularnewline
4711 & 123 & 123 & 123\tabularnewline
4711 & 1 & 1 & 1\tabularnewline
\bottomrule
\end{longtable}

\begin{longtable}[]{rllc}
\caption{Some hardcoded table}\tabularnewline
\toprule
\textbf{Right} & Left & Default & Center\tabularnewline
\midrule
\endfirsthead
\toprule
\textbf{Right} & Left & Default & Center\tabularnewline
\midrule
\endhead
4711 & 12 & 12 & 12\tabularnewline
4711 & 123 & 123 & 123\tabularnewline
4711 & 1 & 1 & 1\tabularnewline
\bottomrule
\end{longtable}

This is of course a nonsensical filter, but the table parameter provides the content, caption and alignments of the table.
Therefore the returned LaTeX code can be created as needed:

  • the @-expressions could be removed, or
  • the \columncolor solution could be implemented
  • furthermore \rowcolor could be used instead of the global \rowcolors

@Wandmalfarbe
Copy link
Owner Author

have you considered lua-filters as a workaround for this issue?

Yes, I thought about that but I don't have much experience with pandoc filters or Lua. I would have made a bash script that replaces the string @{} in the generated LaTeX and compiles the document with pdfLaTeX.

A filter seems much nicer and could potentially solve more than one problem as you mentioned. Unfortunately I don't have much time at the moment so a workaround with filters has to wait.

@ConnorBaker
Copy link

I didn't see it mentioned anywhere, but I believe that this commit is the root of this issue:

jgm/pandoc@229c225

Mind you, I haven't reverted it and recompiled pandoc to confirm, but the commit message leads me to believe that it is.

I started typing my notes up using markdown instead of LaTeX, and began using your awesome template as a result. (@Wandmalfarbe you did a fantastic job -- I really appreciate you sharing it!) The overlap between the coloring and the rules bothered me, which led me to this issue.

I thought about writing a filter (which would have been apt considering I'm currently self-teaching Haskell, and that pandoc is written in Haskell), but I don't think that one could help us here: filters operate on the abstract syntax tree (AST) generated by pandoc, but this issue only surfaces after the AST is transformed in LaTeX source (since inserting @{} is a choice made by pandoc's LaTeX writer and is not present in the AST).

As far as I can tell, we could do any of the following

  1. Make a flag for the pandoc LaTeX writer which tells it to opt out of making the table smaller (which would be useful for other templates that color the rows of tables)
  2. Politely ask the maintainer of pandoc to revert the choice to use @{} to by default shorten the length of the rules of tables , as it is an aesthetic one that, in this case, seems to break the appearance of the common practice of highlighting rows of a table. (The maintainer did make a good case in Disable the generation of smaller tables when using LaTeX/PDF? jgm/pandoc#3929 (comment) that this is a problem with the packages available to highlight rows, as it definitely should be sensitive to the presence of@{}.)
  3. Create a script which runs pandoc to generate the LaTeX files, removes the @-expression, and then compiles the resulting file (which is what @Wandmalfarbe suggested above)

I think my favorite option is the first, because it would extend pandoc's functionality, and given the availability of the source code, might be something I could do as a summer project (I'm currently in college studying computer science and working, so not a lot of free time).

The second option doesn't seem viable because, (and this is still speculation because I haven't recompiled pandoc with the commit reverted) if it is such a simple fix, then there's probably reason that it's still there. Taking the alternative approach of getting the maintainers of LaTeX packages which can be used to color rows to update their packages seems unlikely, and I don't know enough about how to develop or modify such packages.

The third option definitely works, and might possibly be implemented by a simple bash script or something similar... but I feel that this signals a failure in tooling.

Anyway, apologies if this was all already known. I didn't see it anywhere and thought I'd share my findings.

@cagix
Copy link
Contributor

cagix commented Jul 24, 2019

@Wandmalfarbe Until a better solution (fix to pandoc, lua filter, ...) is implemented, couldn't it be a simple workaround to disable column colours via an option to the eisvogel template?!

Wandmalfarbe added a commit that referenced this issue Aug 4, 2019
@cagix
Copy link
Contributor

cagix commented Sep 24, 2019

thanks :)

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

No branches or pull requests

4 participants