-
-
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
Add an option to prevent colgroup column width ratios being added to pipe tables #8139
Comments
Here's a Lua filter that does this: function Table (tbl)
tbl.colspecs = tbl.colspecs:map(function (colspec)
local align = colspec[1]
local width = nil -- default width
return {align, width}
end)
return tbl
end See the Manipulate Markdown via Pandoc Lua filters in the R Markdown Cookbook for more info on this approach. |
I think you meant "more than the column width." |
I think the filter solution is probably adequate. It's more complicated if you need this to apply to some but not all tables, but perhaps then you could enclose the relevant tables in a Div? |
Thanks @tarleb and @jgm, the filter does exactly what I want it to do. However, if this is not preferred, perhaps the docs could be updated to point to this filter solution to make it easier to find? |
Also, I've just discovered that this filter doesn't work with older versions such as Pandoc 2.5 (pandoc-types 1.17.5.4) which is the default on Ubuntu 20.04. Is there a way to fix the filter to work on older versions? I'm getting this error:
I'm guessing that |
I believe that this version should work with both pandoc versions, but I didn't test it: function Table (tbl)
if PANDOC_VERSION >= '2.10' then
tbl.colspecs = tbl.colspecs:map(function (colspec)
local align = colspec[1]
local width = nil -- default width
return {align, width}
end)
else
for i, w in ipairs(tbl.widths) do
tbl.widths[i] = 0
end
end
return tbl
end |
Related issue: #2165 |
Thanks @tarleb. I had to tweak it slightly as I was getting the error -- Unset the width attribute of HTML colspecs in tables
-- See https://github.com/jgm/pandoc/issues/8139
function Table (tbl)
if PANDOC_VERSION[1] >= 2 and PANDOC_VERSION[2] >= 10 then
tbl.colspecs = tbl.colspecs:map(function (colspec)
local align = colspec[1]
local width = nil -- default width
return {align, width}
end)
else
for i, w in ipairs(tbl.widths) do
tbl.widths[i] = 0
end
end
return tbl
end |
I'm adding a FAQ entry which should make this more discoverable. |
The version check in the code above doesn't seem to work once you get to Pandoc version 3, since the minor version is no longer 10 or greater. I think what we want is: -- Unset the width attribute of HTML colspecs in tables
-- See https://github.com/jgm/pandoc/issues/8139
function Table (tbl)
if PANDOC_VERSION[1] > 2 or (PANDOC_VERSION[1] == 2 and PANDOC_VERSION[2] >= 10) then
tbl.colspecs = tbl.colspecs:map(function (colspec)
local align = colspec[1]
local width = nil -- default width
return {align, width}
end)
else
for i, w in ipairs(tbl.widths) do
tbl.widths[i] = 0
end
end
return tbl
end This should work until a future breaking change alters how column specs are accessed. |
I was able to work around this by adding: /* style.css */
col {
width: auto !important;
} To the CSS stylesheet, then passing |
If you create a markdown table using the pipe tables extension, and any line of the markdown source is more than the column width, then the relative cell widths in the output are calculated based on the ratio of dashes under the headings in the markdown.
For HTML output, this results in the insertion of an HTML
colgroup
block which forces the proportions of the cells.However, I'm using R Markdown to insert computed values into my table cells, which means that the cells could realisticly have any number of characters in them, and I'd prefer to rely on the default column widths that the tables would have if there were no
colgroup
block at all.I understand that if I use any of the other table extensions I'll get this, but as I'm inserting computed column values it makes the other table exentions unviable, as they rely on getting the spacing lined up exactly right, which I can't do here.
The workaround I have found to prevent this is to use the pandoc argument
--columns 1000
, but it would be nice to be able to explicitly disable this feature.The text was updated successfully, but these errors were encountered: