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

Problem removing table top or bottom rules with latex command in pandoc 2.19 #8223

Closed
gnpan opened this issue Aug 11, 2022 · 15 comments
Closed

Comments

@gnpan
Copy link

gnpan commented Aug 11, 2022

Pandoc 2.19, macOS 12.5

With previous pandoc versions, table top/mid/bottom rules could be removed by including appropriate latex commands under header-includes. The following example with pandoc 2.19 removes top and bottom rules but adds two parentheses (), as shown in attached pdf. Same with grid tables.

---
header-includes: 
  - \let\toprule\relax
  - \let\bottomrule\relax
---

| c1 | c2 | c3 |
|:---|:---|:---|
| r1 | a | b |
| r2 | c | d | 

test.pdf
test.md

@gnpan gnpan added the bug label Aug 11, 2022
@tarleb
Copy link
Collaborator

tarleb commented Aug 11, 2022

See #8001 for the reasons behind this change, but maybe we can make that work again: \midrule is always followed by either \endhead or \endfirsthead, so the parens can be omitted. Same for \bottomrule, which will always be followed by \end{longtable}. This leaves \toprule: replacing \toprule with \toprule\relax seems to have no adverse effects in my tests.

For the time being, you can use \renewcommand{\toprule}[2]{} etc. to remove the rules.

@jgm
Copy link
Owner

jgm commented Aug 13, 2022

In this connection we should also consider
#7421 (comment)

Revisiting my decision to add the () instead of \relax: based on tests with test/tables.native, it seems that the reason I did this was because with \midrule\relax and \bottomrule\relax we get extra vertical space beneath the midrule and the bottomrule. Does anyone understand why? It seems that using \relax instead of () would perhaps solve both problems, but we don't want this vertical space.

@jgm
Copy link
Owner

jgm commented Aug 22, 2022

replacing \toprule with \toprule\relax seems to have no adverse effects in my tests.

When I tried this, I got extra white space in the headerless tables in test/tables.native. e.g.

Screen Shot 2022-08-22 at 8 16 28 AM

With the current setup we don't get that blank line after the top rule.

@tarleb
Copy link
Collaborator

tarleb commented Aug 22, 2022

Oh. I guess this issue should be closed then. I don't know why I missed the empty line, or why I got a different result.

@tarleb tarleb added enhancement and removed bug labels Aug 22, 2022
@jgm
Copy link
Owner

jgm commented Aug 22, 2022

I'd like to keep this open until I can understand why the \relax doesn't work. Maybe a TeX guru can help.

@tarleb
Copy link
Collaborator

tarleb commented Aug 22, 2022

I found my mistake: I was experimenting in a raw tex file and had removed the \endhead command. I get the blank line when I add it back in.

@jgm
Copy link
Owner

jgm commented Aug 22, 2022

See also #8242.

@marcin-serwin
Copy link
Contributor

marcin-serwin commented Nov 5, 2022

The reason \relax does not work is that LaTeX interprets it as part of the table cell. Thus, the headerless table in test/tables.native is roughly interpreted as

| \relax |     |     |     |
|     12 | 12  | 12  |  12 |
|    123 | 123 | 123 | 123 |
|      1 | 1   |  1  |   1 |

And then \relax is expanded to nothing, leaving empty first row in the final table. The simplest fix would be to replace it with \noalign{} which inserts empty vertical box between table rows, thus not affecting the cell content. It is worth noting that \noalign is a TeX primitive, so it's not idiomatic LaTeX.

\documentclass{article}

\usepackage{booktabs}
\usepackage{longtable}

\begin{document}

\begin{longtable}{@{}lll@{}}
	\toprule\noalign{}
	\endhead
	(1) & 2 & 3 \\
	a & b & c \\
	\bottomrule\noalign{}
\end{longtable}

\begin{longtable}{@{}lll@{}}
	\toprule\noalign{}
	(1) & 2 & 3 \\
	\endhead
	a & b & c \\
	\bottomrule\noalign{}
\end{longtable}

\end{document}

image

@tarleb
Copy link
Collaborator

tarleb commented Dec 20, 2022

It seems like all questions around this issue have been answered. Closing.

@tarleb tarleb closed this as completed Dec 20, 2022
@jgm
Copy link
Owner

jgm commented Dec 20, 2022

I was thinking we should keep this open in order to explore the solution proposed here:

The simplest fix would be to replace it with \noalign{} which inserts empty vertical box between table rows, thus not affecting the cell content.

Unless I was misunderstanding and this isn't a potential solution?

@tarleb
Copy link
Collaborator

tarleb commented Dec 20, 2022

Oh, I had missed that!

@tarleb tarleb reopened this Dec 20, 2022
@paul-kelleher
Copy link

I've been trying to implement zebra shading in a longtable following the discussion here. I managed to get something that looked good by adding this before the table in my markdown file:

\rowcolors{2}{}{gray!25}
\setlength{\tabcolsep}{0pt}
\apptocmd{\toprule}{\hiderowcolors}{}{}
\apptocmd{\endhead}{\showrowcolors}{}{}
\apptocmd{\endfirsthead}{\showrowcolors}{}{}

The only problem was that two parentheses "()" were added into the top of the table. I then found my way to this thread. Following the discussion here, I discovered that if I used pandoc to compile my markdown file to LaTeX, I could get rid of the parentheses by replacing the instance of "\toprule()" to "\toprule\noalign{}" in the LaTeX file.

I guess my question is: what (and where) can I include in my markdown file so that Pandoc produces a PDF without the parentheses? I mean, I guess I can compile to LaTeX and make that change manually, but it'd be great if there were another way. Thanks!

@jgm
Copy link
Owner

jgm commented Jan 4, 2023

There's no way to get this fix with pandoc itself. You could pipe output through sed or perl.
I think we should change pandoc to yield \toprule\noalign{} instead of \toprule(). That should be a simple fix.

@jgm jgm closed this as completed in 7a82686 Jan 4, 2023
@marcin-serwin
Copy link
Contributor

@jpk3333 As a workaround you can also modify your code to look like this

\rowcolors{2}{}{gray!25}
\setlength{\tabcolsep}{0pt}
% \apptocmd{\toprule}{\hiderowcolors}{}{}
\makeatletter
\NewCommandCopy\@oldtoprule\toprule
\RenewExpandableDocumentCommand\toprule{d()m}{\@oldtoprule\hiderowcolors#2}
\makeatother
\apptocmd{\endhead}{\showrowcolors}{}{}
\apptocmd{\endfirsthead}{\showrowcolors}{}{}

though it's a bit hacky, so double check that it works as expected. (You may have to add \usepackage{xparse} in the preamble if your LaTeX version is old.)

@paul-kelleher
Copy link

@marcin-serwin It worked! 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

5 participants