Skip to content

Commit

Permalink
LaTeX writer: don't treat table as "simple" if they have col widths.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jgm committed Oct 18, 2023
1 parent fa3513b commit f4baa88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
22 changes: 13 additions & 9 deletions src/Text/Pandoc/Writers/LaTeX/Table.hs
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/tables/students.latex
Expand Up @@ -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 \\
Expand Down

0 comments on commit f4baa88

Please sign in to comment.