diff options
author | John MacFarlane <jgm@berkeley.edu> | 2020-10-29 12:10:05 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2020-10-29 12:10:05 -0700 |
commit | bd7c9eb32be7c5499f4a50cb4b5f138f9eb919e8 (patch) | |
tree | 420c6c75fe95d425b3a0089e6e37e755e94dee5d /src | |
parent | 517c55dae7a33a858f73609a90972f5da05dd1b1 (diff) | |
download | pandoc-bd7c9eb32be7c5499f4a50cb4b5f138f9eb919e8.tar.gz |
LaTeX writer: Improved calculation of table column widths.
We now have LaTeX do the calculation, using `\tabcolsep`.
So we should now have accurate relative column widths no
matter what the text width.
The default template has been modified to load the calc
package if tables are used.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 28b4efca4..f7775318a 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -851,9 +851,6 @@ tableRowToLaTeX :: PandocMonad m -> [[Block]] -> LW m (Doc Text) tableRowToLaTeX header aligns widths cols = do - -- scale factor compensates for extra space between columns - -- so the whole table isn't larger than columnwidth - let scaleFactor = 0.97 ** fromIntegral (length aligns) let isSimple [Plain _] = True isSimple [Para _] = True isSimple [] = True @@ -861,9 +858,10 @@ tableRowToLaTeX header aligns widths cols = do -- simple tables have to have simple cells: let widths' = if all (== 0) widths && not (all isSimple cols) then replicate (length aligns) - (scaleFactor / fromIntegral (length aligns)) - else map (scaleFactor *) widths - cells <- mapM (tableCellToLaTeX header) $ zip3 widths' aligns cols + (1 / fromIntegral (length aligns)) + else widths + let numcols = length widths' + cells <- mapM (tableCellToLaTeX header numcols) $ zip3 widths' aligns cols return $ hsep (intersperse "&" cells) <> "\\tabularnewline" -- For simple latex tables (without minipages or parboxes), @@ -890,11 +888,12 @@ displayMathToInline :: Inline -> Inline displayMathToInline (Math DisplayMath x) = Math InlineMath x displayMathToInline x = x -tableCellToLaTeX :: PandocMonad m => Bool -> (Double, Alignment, [Block]) +tableCellToLaTeX :: PandocMonad m + => Bool -> Int -> (Double, Alignment, [Block]) -> LW m (Doc Text) -tableCellToLaTeX _ (0, _, blocks) = +tableCellToLaTeX _ _ (0, _, blocks) = blockListToLaTeX $ walk fixLineBreaks $ walk displayMathToInline blocks -tableCellToLaTeX header (width, align, blocks) = do +tableCellToLaTeX header numcols (width, align, blocks) = do beamer <- gets stBeamer externalNotes <- gets stExternalNotes inMinipage <- gets stInMinipage @@ -912,9 +911,12 @@ tableCellToLaTeX header (width, align, blocks) = do AlignCenter -> "\\centering" AlignDefault -> "\\raggedright" return $ "\\begin{minipage}" <> valign <> - braces (text (printf "%.2f\\columnwidth" width)) <> + braces (text (printf + "(\\columnwidth - %d\\tabcolsep) * \\real{%.2f}" + (numcols - 1) width)) <> halign <> cr <> cellContents <> "\\strut" <> cr <> "\\end{minipage}" +-- (\columnwidth - 8\tabcolsep) * \real{0.15} notesToLaTeX :: [Doc Text] -> Doc Text notesToLaTeX [] = empty |