-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
longtable not compatible with 2-column LaTeX documents #1023
Comments
Regarding the possibility of using longtable in 2-column documents, I found this thread on a Stack Exchange site, but it is not promising: http://tex.stackexchange.com/questions/39686/longtable-alternative-for-twocolumn-documents |
I have a related issue that probably isn't worth opening another issue ticket for. Rather than a "resurrect |
As a workaround, one can |
@scmbradley is it really that simple? |
@nrnrnr @scmbradley From what I can tell, if you use tabular, you also have to add table environments. I can do this manually, but I don't see a way to do it with the template. |
It would be indeed very useful if |
I solved this by using this tip: replacing |
When replacing To center the table, wrap them between Here's the code I add to the build process (in Ruby).
|
Hey everyone, sorry for resurrecting this one -- do we have any way of resolving this beyond using |
If there were no other differences, you could do a
But there are some differences between the two environments, +++ Nikos Vasilakis [Aug 17 15 20:32 ]:
|
Thanks John! This does not work though, I think because the generated table code has a number extra stuff -- for instance: However, I am now thinking: wouldn't a solution based on detecting return ( if ("supertabular" `isInfixOf` (writerTemplate opts)) then
( "\\begin{supertabular}[c]" <>
braces ("@{}" <> colDescriptors <> "@{}")
$$ capt
$$ headers
$$ vcat rows'
$$ "\\end{supertabular}"
)
else -- normal old behavior
( "\\begin{longtable}[c]" <>
braces ("@{}" <> colDescriptors <> "@{}")
-- the @{} removes extra space at beginning and end
$$ capt
$$ "\\toprule"
$$ headers
$$ endhead
$$ vcat rows'
$$ "\\bottomrule"
$$ "\\end{longtable}"
)
) |
I don't really like making behavior sensitive to what's in What about doing what I suggested, but with supertabular +++ Nikos Vasilakis [Aug 17 15 23:23 ]:
|
Changing the lines you suggested to: \let\longtable\supertabular
\let\endlongtable\endsupertabular while adding: \usepackage{supertabular}
\usepackage{booktabs} ..still doesn't work:
My goal is to have tables in two-column latex documents. Do you use a different way to achieve a similar result in your documents? Regarding the psudo-patch I proposed, I know it's not optimal, it's just to get people going until a proper solution gets in. Another simple idea might be to just default to |
+++ Nikos Vasilakis [Aug 18 15 10:45 ]:
I've never tried this.
The problem is that if we do support it in some versions, One possibility would be to check for What are the advantages of supertabular or xtab over table? |
As a workaround, someone (thanks!) has created a filter for using tabular instead of longtable in twocolumn environment (e.g. https://groups.google.com/forum/#!msg/pandoc-discuss/RUC-tuu_qf0/h-H3RRVt1coJ To use it:
e.g. |
I tried this, and there are a number of issues with
in the header; you'll need to add this yourself through
I'd be open to adding an option to pandoc to use regular +++ Aziz Alto [Nov 29 15 02:52 ]:
|
That's right! however in my case the filter does work with I add \usepackage{booktabs} to the header of the template I use. Also another option (instead of using booktabs) would be to replace The tables with long cells work fine in the I have not tried the footnotes. Thank you. |
I would really like to see this get resolved without resorting to running external scripts and such. Since two-column formats are pretty common for LaTeX documents would it be possible to have a separate output mode for them as part of pandoc itself? |
I'd like to solve this too. What I need to know is how to reproduce our current table features using regular tabular. As noted above, two features that are a bit tricky are (a) footnotes in table cells and (b) relative widths in columns. Once I've got this down, we could do several things. One option would be to have a command-line option to use regular tabular instead of longtable. Another would be to have tables inside a specially marked div treated specially (perhaps the special behavior should be longtable instead of regular tabular). |
I'd be willing to take a crack at this, possibly over the break. It looks like the relevant parts in the LaTeX writer are the functions |
I'd have no trouble doing the Haskell bits. I just need to +++ Shrutarshi Basu [Dec 20 15 13:21 ]:
|
Hi, I have converted a multiline table example from the Pandoc user's guide to use tabular / table, and footnotes (courtesy of http://tex.stackexchange.com/a/35328) as well as relative widths seem to work. The LaTeX code: \documentclass{article}
\usepackage{hyperref}
\usepackage{tablefootnote}
\usepackage{booktabs}
\begin{document}
\begin{table}
\caption{Here's a multiline table without headers.}
\begin{tabular}{ c l r l }
\tabularnewline
\toprule
\toprule
\begin{minipage}[t]{0.15\columnwidth}\centering\strut
First
\strut\end{minipage} &
\begin{minipage}[t]{0.10\columnwidth}\raggedright\strut
row
\strut\end{minipage} &
\begin{minipage}[t]{0.20\columnwidth}\raggedleft\strut
12.0
\strut\end{minipage} &
\begin{minipage}[t]{0.31\columnwidth}\raggedright\strut
Example of a row that spans multiple lines.\tablefootnote{Footnotes also work.}
\strut\end{minipage}\tabularnewline
\begin{minipage}[t]{0.15\columnwidth}\centering\strut
Second
\strut\end{minipage} &
\begin{minipage}[t]{0.10\columnwidth}\raggedright\strut
row
\strut\end{minipage} &
\begin{minipage}[t]{0.20\columnwidth}\raggedleft\strut
5.0
\strut\end{minipage} &
\begin{minipage}[t]{0.31\columnwidth}\raggedright\strut
Here's another one. \tablefootnote{Another footnote.}Note the blank line between rows.
\strut\end{minipage}\tabularnewline
\bottomrule
\end{tabular}
\end{table}
\end{document} |
Hi, will there be a command option/metadata variable for us to choose which kind of table will be used in LaTeX? From another thread it seems pandoc had changed the package it use for table but the old way wasn't kept. It would be nice if pandoc allow a choice of which conversion to use. And is the use of table package open for discussion? I know that MultiMarkdown use tabulary, and probably tabularx has better footnote in table support (I once need to manually turn the tabulary table in mmd to a tabularx one). And I heard that tabu is supposed to be the newest and best package for table but haven't tried it yet. |
See #2384, #1023, and related discussions in pandoc-discuss. +++ ickc [Apr 26 16 22:56 ]:
|
@jgm, what do you think about my solution? I think it should be fairly easy to adapt the existing table export code in pandoc to the format I proposed, and I do not see any problems with it. |
I've long had the goal of trying to stick to packages in the In the end, it might still be worth considering. Maybe +++ Michael Färber [Apr 14 16 10:00 ]:
|
I understand. How about then leaving longtable as the default and creating a command-line option to use tablefootnote? This would not create a dependency for users that "just want some table", and if they need non-breaking tables desperately enough to use a new command-line option, they are probably also willing to depend on some extra package. :) (At least I am desperate enough. The table situation is by far my greatest Pandoc problem by far.) |
Thanks for your solution. It is working well for me. But I was wondering where do you define your filter? |
Have a look at the |
Thanks for your quite reply! I tried adding your filter in a script named """ Pandoc filter to fix the issue with longtable not compatible
with 2-column latex documents
See https://github.com/jgm/pandoc/issues/1023#issuecomment-656769330
"""
import pandocfilters as pf
def supertabular(key, value, format, meta):
"""
NOTE: This filter expects a modification to the default template
"""
if key == 'Table' and 'processed' not in value[0][1]:
caption = value[1]
cap = pf.stringify(caption)
cmd = f'\\renewcommand\\tcap{{{cap}}}'
value[0][1].append('processed')
value[1] = {'t': 'Caption', 'c': [None, []]}
mytable = pf.elt('Table', len(value))
return [pf.RawBlock('latex', cmd), mytable(*value)]
if __name__ == '__main__':
pf.toJSONFilter(supertabular) I also added the latex package supertabular in a separate file ( \usepackage{supertabular}
\newcommand\tcap{}
\renewenvironment{longtable}{\begin{center}\bottomcaption{\tcap}\begin{supertabular}}{\end{supertabular}\end{center}}
\renewcommand{\endhead}{} My minimalist markdown file ---
---
### Test Table
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |
<!-- \renewcommand\tcap{Table styles. \label{tab:1}} -->
Table: Table styles. \label{tab:1}
Seen in table \ref{tab:1}, Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
But when I run the command below: pandoc article.md \
--citeproc \
--from=markdown+tex_math_single_backslash+tex_math_dollars+raw_tex \
--to=latex \
--output=build/article-print-doublecols.pdf \
--pdf-engine=xelatex \
-M classoption=twocolumn \
--include-in-header="layout/supertabular.tex" \
--filter="layout/twocolumns_table_fix.py" I got this error: Error running filter layout/twocolumns_table_fix.py:
Error in $.blocks[4]: When parsing the constructor Caption of type Text.Pandoc.Definition.Caption expected Array but got Object. Any idea why I got this error? |
@SamKacer Did you use the command below to set the caption? \renewcommand\tcap{My Caption} This worked for me |
@lhoupert oh, right. I can't believe I missed that. I just copy pasted that in without actually reading it. that works fine. thanks for pointing that out |
Apparently something has changed in pandoc in the meantime and my filter is not correct anymore.
Then I had to remove your html comment from your example and then it worked for me. Almost. |
Thanks very much @Bustel for debugging me on this! I managed to find a solution to my problem without having to install other package :-) The idea is to save the latex reference before "stringifyïng" the caption, so I created a short function for that ( """ Pandoc filter to fix the issue with longtable not compatible
with 2-column latex documents
See https://github.com/jgm/pandoc/issues/1023#issuecomment-656769330
"""
import pandocfilters as pf
from pandocfilters import walk
def return_latex_ref(x):
"""Walks the tree x and returns the latex reference.
"""
result = []
def go(key, val, format, meta):
if key in 'RawInline':
if val[0] == 'tex' and '\\label' in val[1]:
result.append(val[1])
walk(x, go, "", {})
return ''.join(result)
def supertabular(key, value, format, meta):
"""
NOTE: This filter expects a modification to the default template
"""
if key == 'Table' and 'processed' not in value[0][1]:
caption = value[1]
cap = pf.stringify(caption) + ' ' + return_latex_ref(caption)
cmd = f'\\renewcommand\\tcap{{{cap}}}'
value[0][1].append('processed')
value[1] = [None, []]
mytable = pf.elt('Table', len(value))
return [pf.RawBlock('latex', cmd), mytable(*value)]
if __name__ == '__main__':
pf.toJSONFilter(supertabular) |
@lhoupert solution works for me. The only thing I'd like is the possibility of using default pandoc-cross-ref notation | | Grosor [mm] | Factor de reducción |
|-----|-------------|---------------------|
| HVL | 10.1 | 2 |
| QVL | 19 | 4 |
| TVL | 29.9 | 10 |
: Valores de HVL, QVL y TVL reportados \label{tbl:name}
This works [@tbl:name]. |
There is a new error: It happens when the size the table is bigger than the width of the column. The next couple of lines appear in the latex output once the above condition is triggered. \begin{longtable}[]{@{}
>{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.35}}
>{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.22}}@{}}\real{0.22}}@{}} |
Kind of off topic, but for anyone just trying to get a long table from pandoc to span over two columns, wrap it in |
I just found a solution to this on the TeX stack exchange. If you include a header file that looks like this: \makeatletter
\let\oldlt\longtable
\let\endoldlt\endlongtable
\def\longtable{\@ifnextchar[\longtable@i \longtable@ii}
\def\longtable@i[#1]{\begin{figure}[t]
\onecolumn
\begin{minipage}{0.5\textwidth}
\oldlt[#1]
}
\def\longtable@ii{\begin{figure}[t]
\onecolumn
\begin{minipage}{0.5\textwidth}
\oldlt
}
\def\endlongtable{\endoldlt
\end{minipage}
\twocolumn
\end{figure}}
\makeatother You can just redefine the Source: https://tex.stackexchange.com/a/224096 This could have some side effects I don't know about, but everything seems fine from what I can see. |
None of the recommended solutions above worked for me. I do not want my tables to float. And mysteriously a solution I had from a few years back is now broken and giving a \noalign error that I cannot sort out. I put this in the preamble:
And it is working again. I suppose my tables will not work across pagebreaks, but I also do not use long tables. PS. One of the early comments in this thread confuses |
None of the proposals above do work for me though :/ I can't use tables in Pandoc anymore. I have to use a two-column template. Original error is Tryin to use tabular:
results in BTW, the table is as simple as
which gets converted to
No idea what I could do :( |
Yeah I tried that, however it doesn't align properly in my document. EDIT: Fixed by moving the |
|
I have tried all the options here and various other things (like Lua filters) and nothing seems to work. Would really love to see a fix that is at least compatible with simple tables in a two-column format! :) |
@jankap I got your code to work by adding to the above:
|
I'm currently using LaTeX with https://ctan.org/pkg/tabularray in markdown to render my tables in two-col mode... |
For anyone who just wants the normal tabular, this is a Pandoc filter ChatGPT wrote that seems to do just that: https://github.com/SichangHe/JSphere/blob/6dd9bc1cabc84644cbde6e3441251837b421031c/table_workaround_filter.lua I don't know how to do No idea why Pandoc reinvents the table. Hopes this helps someone though. |
OK, I messed around with https://gist.github.com/wgroeneveld/9dbeb0d0b60c6cb5d8dfe9b938c5e94e?permalink_comment_id=5150542#gistcomment-5150542 and ended up with the following panflute filter that respects spaces and verbatim in tables, and works with cross referencing and citations: import sys
from panflute import *
def replace_longtables_with_tabular(elem, doc):
try:
def get_text(item):
if isinstance(item, Str):
return item.text.replace('_', r'\_')
elif isinstance(item, Plain):
return ''.join([get_text(i) for i in item.content])
elif isinstance(item, ListContainer):
return ''.join([get_text(i) for i in item])
elif isinstance(item, Code):
return '\\verb|' + (item.text) + '|'
elif isinstance(item, RawInline):
return item.text
elif isinstance(item, Cite):
return ''.join(stringify(elem) for elem in item.content)
elif str(item) == 'Space':
return ' '
else:
return str(item)
def caption():
if elem.caption and elem.caption.content:
return '\\caption{' + get_text(elem.caption.content) + '}\n' + \
'\\label{tbl:' + get_text(elem.caption.content).replace(' ', r'-').translate(str.maketrans("", "", "();,.")) + '}\n'
return ''
def tabular():
return '\\begin{tabular}{' + 'l' * elem.cols + '}\n\\hline\n'
def headers():
if elem.head and elem.head.content:
return ' & '.join([get_text(cell.content) for cell in elem.head.content[0].content]) + '\\\\\n\\hline\n'
return ''
def items():
rows = []
for body in elem.content:
for row in body.content:
rows.append(' & '.join([get_text(cell.content) for cell in row.content]) + '\\\\')
return '\n'.join(rows) + '\n'
result = '\\begin{table*}[t]\n\\centering\n' + \
caption() + \
tabular() + \
headers() + \
items() + \
'\\hline\n\\end{tabular}\n\\end{table*}'
print("Table processed successfully", file=sys.stderr)
return RawBlock(result, 'latex')
except Exception as e:
print(f"Error processing table: {str(e)}", file=sys.stderr)
return elem
def prepare(doc):
pass
def action(elem, doc):
if doc.format != 'latex':
return None
if isinstance(elem, Table):
print("Table found!", file=sys.stderr)
return replace_longtables_with_tabular(elem, doc)
return None
def finalize(doc):
pass
# keep this structure: see http://scorreia.com/software/panflute/guide.html
def main(doc=None):
return run_filter(action,
prepare=prepare,
finalize=finalize,
doc=doc)
if __name__ == '__main__':
main() |
For some time I have been using pandoc to create two-column PDF documents via LaTeX. (This can be accomplished with some abuse of the
fontsize
variable.) However, in the transition from 1.9.x to 1.11.1, all tables appear to have becomelongtable
environments, and when presented with two-column format,longtable
falls over:I see in past issues that the transition from ctable to longtable was decided on a while back, but I really hate to lose the ability to create two-column documents, which I use heavily. I also understand the issue of wanting to stick with relatively standard LaTeX packages.
Is it possible that the old
ctable
back end could be resurrected via some kind of command-line option? It sounds horrible, but I can't think of a better solution.The text was updated successfully, but these errors were encountered: