diff options
| author | Albert Krewinkel <[email protected]> | 2022-09-21 11:27:06 +0200 |
|---|---|---|
| committer | Albert Krewinkel <[email protected]> | 2022-09-21 12:03:41 +0200 |
| commit | b38292c2346ebea690eada91a5ac1e0addaa3c0b (patch) | |
| tree | 85c29297aa45cd0b409b4b94827be67c6ad9c713 | |
| parent | 47d09df6a583587c5d8aadd4b3fc7c009957b219 (diff) | |
LaTeX writer: do not repeat caption on headless tables
The caption of headless tables was repeated on each page that contained
part of the table. It is now made part of the "first head", i.e. the
table head that is printed only once.
| -rw-r--r-- | src/Text/Pandoc/Writers/LaTeX/Table.hs | 23 | ||||
| -rw-r--r-- | test/command/8219.md | 1 |
2 files changed, 12 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX/Table.hs b/src/Text/Pandoc/Writers/LaTeX/Table.hs index aca408d5d..ceed60f88 100644 --- a/src/Text/Pandoc/Writers/LaTeX/Table.hs +++ b/src/Text/Pandoc/Writers/LaTeX/Table.hs @@ -54,17 +54,17 @@ tableToLaTeX inlnsToLaTeX blksToLaTeX tbl = do -- repeated on all pages that contain a part of the table. We avoid this by -- making the caption part of the first head. The downside is that we must -- duplicate the header rows for this. - firsthead <- if isEmpty capt || isEmptyHead thead - then return empty - else (\firstrows -> capt $$ firstrows $$ "\\endfirsthead") <$> - headToLaTeX blksToLaTeX colCount thead - head' <- if isEmptyHead thead - then return "\\toprule()" - -- avoid duplicate notes in head and firsthead: - else headToLaTeX blksToLaTeX colCount - (if isEmpty firsthead - then thead - else walk removeNote thead) + head' <- do + let mkHead = headToLaTeX blksToLaTeX colCount + case (not $ isEmpty capt, not $ isEmptyHead thead) of + (False, False) -> return "\\toprule()" + (False, True) -> mkHead thead + (True, False) -> return (capt $$ "\\toprule()" $$ "\\endfirsthead") + (True, True) -> do + -- avoid duplicate notes in head and firsthead: + firsthead <- mkHead thead + repeated <- mkHead (walk removeNote thead) + return $ capt $$ firsthead $$ "\\endfirsthead" $$ repeated rows' <- mapM (rowToLaTeX blksToLaTeX colCount BodyCell) $ mconcat (map bodyRows tbodies) <> footRows tfoot modify $ \s -> s{ stTable = True } @@ -73,7 +73,6 @@ tableToLaTeX inlnsToLaTeX blksToLaTeX tbl = do $ "\\begin{longtable}[]" <> braces ("@{}" <> colDescriptors tbl <> "@{}") -- the @{} removes extra space at beginning and end - $$ firsthead $$ head' $$ "\\endhead" $$ vcat rows' diff --git a/test/command/8219.md b/test/command/8219.md index 52279cf42..d19e3584c 100644 --- a/test/command/8219.md +++ b/test/command/8219.md @@ -7,6 +7,7 @@ \begin{longtable}[]{@{}ll@{}} \caption{}\label{test}\tabularnewline \toprule() +\endfirsthead \endhead one & two \\ \bottomrule() |
