From f4baa88f4267e2056269efa71ce78ee290b0e9aa Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 17 Oct 2023 21:09:31 -0700 Subject: [PATCH] LaTeX writer: don't treat table as "simple" if they have col widths. This should help fix a problem wherein some grid tables with colspans were overly wide. See #9140. The example given there still produces suboptimal output (overlapping text), so not closing yet. --- src/Text/Pandoc/Writers/LaTeX/Table.hs | 22 +++++++++++++--------- test/tables/students.latex | 6 +++--- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Text/Pandoc/Writers/LaTeX/Table.hs b/src/Text/Pandoc/Writers/LaTeX/Table.hs index 1d9b117ca6a4..ee5c62a3bd5c 100644 --- a/src/Text/Pandoc/Writers/LaTeX/Table.hs +++ b/src/Text/Pandoc/Writers/LaTeX/Table.hs @@ -47,11 +47,13 @@ tableToLaTeX :: PandocMonad m tableToLaTeX inlnsToLaTeX blksToLaTeX tbl = do let (Ann.Table (ident, _, _) caption specs thead tbodies tfoot) = tbl CaptionDocs capt captNotes <- captionToLaTeX inlnsToLaTeX caption ident - let isSimpleTable = all (all isSimpleCell) $ mconcat - [ headRows thead - , concatMap bodyRows tbodies - , footRows tfoot - ] + let isSimpleTable = + all ((== ColWidthDefault) . snd) specs && + all (all isSimpleCell) + (mconcat [ headRows thead + , concatMap bodyRows tbodies + , footRows tfoot + ]) let removeNote (Note _) = Span ("", [], []) [] removeNote x = x let colCount = ColumnCount $ length specs @@ -111,12 +113,14 @@ tableToLaTeX inlnsToLaTeX blksToLaTeX tbl = do isSimpleCell :: Ann.Cell -> Bool isSimpleCell (Ann.Cell _ _ (Cell _attr _align _rowspan _colspan blocks)) = case blocks of - [Para _] -> True - [Plain _] -> True + [Para _] -> not (hasLineBreak blocks) + [Plain _] -> not (hasLineBreak blocks) [] -> True _ -> False - - + where + hasLineBreak = getAny . query isLineBreak + isLineBreak LineBreak = Any True + isLineBreak _ = Any False -- | Total number of columns in a table. newtype ColumnCount = ColumnCount Int diff --git a/test/tables/students.latex b/test/tables/students.latex index f20aa027c951..802b00c600f6 100644 --- a/test/tables/students.latex +++ b/test/tables/students.latex @@ -20,15 +20,15 @@ Name \endhead \bottomrule\noalign{} \endlastfoot -\multicolumn{2}{@{}l@{}}{% +\multicolumn{2}{@{}>{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{1.0000} + 2\tabcolsep}@{}}{% Computer Science} \\ 3741255 & Jones, Martha \\ 4077830 & Pierce, Benjamin \\ 5151701 & Kirk, James \\ -\multicolumn{2}{@{}l@{}}{% +\multicolumn{2}{@{}>{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{1.0000} + 2\tabcolsep}@{}}{% Russian Literature} \\ 3971244 & Nim, Victor \\ -\multicolumn{2}{@{}l@{}}{% +\multicolumn{2}{@{}>{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{1.0000} + 2\tabcolsep}@{}}{% Astrophysics} \\ 4100332 & Petrov, Alexandra \\ 4100332 & Toyota, Hiroko \\