@@ -647,23 +647,25 @@ blockToLaTeX (Header level (id',classes,_) lst) = do
647647 modify $ \s -> s{stInHeading = False}
648648 return hdr
649649blockToLaTeX (Table caption aligns widths heads rows) = do
650− headers <- if all null heads
651− then return empty
652− else do
653− contents <- (tableRowToLaTeX True aligns widths) heads
654− return ("\\toprule" $$ contents $$ "\\midrule")
655− let endhead = if all null heads
656− then empty
657− else text "\\endhead"
658− let endfirsthead = if all null heads
659− then empty
660− else text "\\endfirsthead"
650+ let toHeaders hs = do contents <- (tableRowToLaTeX True aligns widths) hs
651+ return ("\\toprule" $$ contents $$ "\\midrule")
652+ let removeNote (Note _) = Span ("", [], []) []
653+ removeNote x = x
661654 captionText <- inlineListToLaTeX caption
655+ firsthead <- if isEmpty captionText || all null heads
656+ then return empty
657+ else ($$ text "\\endfirsthead") <$> toHeaders heads
658+ head' <- if all null heads
659+ then return empty
660+ -- avoid duplicate notes in head and firsthead:
661+ else ($$ text "\\endhead") <$>
662+ toHeaders (if isEmpty firsthead
663+ then heads
664+ else walk removeNote heads)
662665 let capt = if isEmpty captionText
663666 then empty
664− else text "\\caption" <> braces captionText <> "\\tabularnewline"
665− $$ headers
666− $$ endfirsthead
667+ else text "\\caption" <>
668+ braces captionText <> "\\tabularnewline"
667669 rows' <- mapM (tableRowToLaTeX False aligns widths) rows
668670 let colDescriptors = text $ concat $ map toColDescriptor aligns
669671 modify $ \s -> s{ stTable = True }
@@ -671,9 +673,9 @@ blockToLaTeX (Table caption aligns widths heads rows) = do
671673 braces ("@{}" <> colDescriptors <> "@{}")
672674 -- the @{} removes extra space at beginning and end
673675 $$ capt
676+ $$ firsthead
674677 $$ (if all null heads then "\\toprule" else empty)
675− $$ headers
676− $$ endhead
678+ $$ head'
677679 $$ vcat rows'
678680 $$ "\\bottomrule"
679681 $$ "\\end{longtable}"