aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs6
-rw-r--r--tests/tables.latex64
2 files changed, 37 insertions, 33 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 98553c421..ab579a326 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -470,9 +470,13 @@ tableRowToLaTeX header aligns widths cols = do
AlignRight -> "\\raggedleft"
AlignCenter -> "\\centering"
AlignDefault -> "\\raggedright"
+ -- 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 toCell 0 _ c = c
toCell w a c = "\\begin{minipage}" <> valign <>
- braces (text (printf "%.2f\\columnwidth" w)) <>
+ braces (text (printf "%.2f\\columnwidth"
+ (w * scaleFactor))) <>
(halign a <> cr <> c <> cr) <> "\\end{minipage}"
let cells = zipWith3 toCell widths aligns renderedCells
return $ hsep (intersperse "&" cells) $$ "\\\\\\noalign{\\medskip}"
diff --git a/tests/tables.latex b/tests/tables.latex
index 82abeb9a5..c27e10461 100644
--- a/tests/tables.latex
+++ b/tests/tables.latex
@@ -54,34 +54,34 @@ Multiline table with caption:
\begin{longtable}[c]{@{}clrl@{}}
\hline\noalign{\medskip}
-\begin{minipage}[b]{0.15\columnwidth}\centering
+\begin{minipage}[b]{0.13\columnwidth}\centering
Centered Header
-\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedright
+\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\raggedright
Left Aligned
-\end{minipage} & \begin{minipage}[b]{0.16\columnwidth}\raggedleft
+\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedleft
Right Aligned
-\end{minipage} & \begin{minipage}[b]{0.34\columnwidth}\raggedright
+\end{minipage} & \begin{minipage}[b]{0.30\columnwidth}\raggedright
Default aligned
\end{minipage}
\\\noalign{\medskip}
\hline\noalign{\medskip}
-\begin{minipage}[t]{0.15\columnwidth}\centering
+\begin{minipage}[t]{0.13\columnwidth}\centering
First
-\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedright
+\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright
row
-\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\raggedleft
+\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft
12.0
-\end{minipage} & \begin{minipage}[t]{0.34\columnwidth}\raggedright
+\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright
Example of a row that spans multiple lines.
\end{minipage}
\\\noalign{\medskip}
-\begin{minipage}[t]{0.15\columnwidth}\centering
+\begin{minipage}[t]{0.13\columnwidth}\centering
Second
-\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedright
+\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright
row
-\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\raggedleft
+\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft
5.0
-\end{minipage} & \begin{minipage}[t]{0.34\columnwidth}\raggedright
+\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright
Here's another one. Note the blank line between rows.
\end{minipage}
\\\noalign{\medskip}
@@ -94,34 +94,34 @@ Multiline table without caption:
\begin{longtable}[c]{@{}clrl@{}}
\hline\noalign{\medskip}
-\begin{minipage}[b]{0.15\columnwidth}\centering
+\begin{minipage}[b]{0.13\columnwidth}\centering
Centered Header
-\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedright
+\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\raggedright
Left Aligned
-\end{minipage} & \begin{minipage}[b]{0.16\columnwidth}\raggedleft
+\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedleft
Right Aligned
-\end{minipage} & \begin{minipage}[b]{0.34\columnwidth}\raggedright
+\end{minipage} & \begin{minipage}[b]{0.30\columnwidth}\raggedright
Default aligned
\end{minipage}
\\\noalign{\medskip}
\hline\noalign{\medskip}
-\begin{minipage}[t]{0.15\columnwidth}\centering
+\begin{minipage}[t]{0.13\columnwidth}\centering
First
-\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedright
+\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright
row
-\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\raggedleft
+\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft
12.0
-\end{minipage} & \begin{minipage}[t]{0.34\columnwidth}\raggedright
+\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright
Example of a row that spans multiple lines.
\end{minipage}
\\\noalign{\medskip}
-\begin{minipage}[t]{0.15\columnwidth}\centering
+\begin{minipage}[t]{0.13\columnwidth}\centering
Second
-\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedright
+\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright
row
-\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\raggedleft
+\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft
5.0
-\end{minipage} & \begin{minipage}[t]{0.34\columnwidth}\raggedright
+\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright
Here's another one. Note the blank line between rows.
\end{minipage}
\\\noalign{\medskip}
@@ -145,23 +145,23 @@ Multiline table without column headers:
\begin{longtable}[c]{@{}clrl@{}}
\hline\noalign{\medskip}
-\begin{minipage}[t]{0.15\columnwidth}\centering
+\begin{minipage}[t]{0.13\columnwidth}\centering
First
-\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedright
+\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright
row
-\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\raggedleft
+\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft
12.0
-\end{minipage} & \begin{minipage}[t]{0.34\columnwidth}\raggedright
+\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright
Example of a row that spans multiple lines.
\end{minipage}
\\\noalign{\medskip}
-\begin{minipage}[t]{0.15\columnwidth}\centering
+\begin{minipage}[t]{0.13\columnwidth}\centering
Second
-\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedright
+\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright
row
-\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\raggedleft
+\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft
5.0
-\end{minipage} & \begin{minipage}[t]{0.34\columnwidth}\raggedright
+\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright
Here's another one. Note the blank line between rows.
\end{minipage}
\\\noalign{\medskip}