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

Col-span and row-span in LaTeX reader #6470

Merged
merged 10 commits into from
Jul 23, 2020
Merged

Col-span and row-span in LaTeX reader #6470

merged 10 commits into from
Jul 23, 2020

Conversation

LaurentRDC
Copy link
Contributor

@LaurentRDC LaurentRDC commented Jun 18, 2020

Hello,

This is a PR for better table support in the LaTeX reader that closes #6311.

This PR adds support for table cells that span more than a single row and single column, as is now supported in pandoc-types 1.21.

So far, this PR supports the \multicolumn and \multirow (from multirow package) commands, as well as nesting them.

Here are usage examples:

Multicolumn:

\begin{table}
    \begin{tabular}{ c c c }
    \multicolumn{2}{c}{1} & 2 \\
    \end{tabular}
    \caption{Caption}
\end{table}

Native output:

[Table ("",[],[]) (Caption Nothing
 [Plain [Str "Caption"]])
 [(AlignCenter,ColWidthDefault)
 ,(AlignCenter,ColWidthDefault)
 ,(AlignCenter,ColWidthDefault)]
 (TableHead ("",[],[])
 [])
 [(TableBody ("",[],[]) (RowHeadColumns 0)
  []
  [Row ("",[],[])
   [Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 2) 
    [Para [Str "1"]]
   ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
    [Plain [Str "2"]]]])]
 (TableFoot ("",[],[])
 [])]

Nesting \multirow and \multicolumn into a 2x2 cell:

\begin{table}
    \begin{tabular}{ c c c c }
        % 2x2 cell
        \multirow{2}{|c|}{\multicolumn{2}{|c|}{1}} & 2 & 3 \\
                                                     4 & 5 \\
    \end{tabular}
    \caption{Caption}
\end{table}

Native output:

[Table ("",[],[]) (Caption Nothing
 [Plain [Str "Caption"]])
 [(AlignCenter,ColWidthDefault)
 ,(AlignCenter,ColWidthDefault)
 ,(AlignCenter,ColWidthDefault)
 ,(AlignCenter,ColWidthDefault)]
 (TableHead ("",[],[])
 [])
 [(TableBody ("",[],[]) (RowHeadColumns 0)
  []
  [Row ("",[],[])
   [Cell ("",[],[]) AlignCenter (RowSpan 2) (ColSpan 2) 
    [Para [Str "1"]]
   ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
    [Plain [Str "2"]]
   ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
    [Plain [Str "3"]]]
  ,Row ("",[],[])
   [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
    [Plain [Str "4"]]
   ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
    [Plain [Str "5"]]]])]
 (TableFoot ("",[],[])
 [])]

@LaurentRDC LaurentRDC changed the title [WIP] Better tables in LaTeX reader Better tables in LaTeX reader Jun 19, 2020
@LaurentRDC LaurentRDC changed the title Better tables in LaTeX reader Col-span and row-span in LaTeX reader Jun 30, 2020
@LaurentRDC
Copy link
Contributor Author

LaurentRDC commented Jul 3, 2020

This is ready for review at your earliest convenience @jgm @tarleb

@tarleb
Copy link
Collaborator

tarleb commented Jul 5, 2020

Thank you for the contribution, and sorry for the wait. I skimmed over it, looks good! I'll have a close look within the next days.

Copy link
Collaborator

@tarleb tarleb left a comment

Choose a reason for hiding this comment

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

See the inline comments, but looks good to me!

Copy link
Collaborator

@tarleb tarleb left a comment

Choose a reason for hiding this comment

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

👍

@LaurentRDC
Copy link
Contributor Author

Is there a reason to wait before merging?

@jgm
Copy link
Owner

jgm commented Jul 23, 2020

This looks good to me and I'll merge it now, thank you.
But does it completely close #6311? For that, we should:

  • attach an identifier to table attributes if a label is present
  • possibly: handle multiple header rows? (I suppose we could identify them by hline or the booktabs equivalents)
  • possibly: table head and foot?

I will keep #6311 open until these are done too.

@jgm jgm merged commit 8c3b5dd into jgm:master Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LaTeX reader - support new table features
3 participants