From f1d330b7b5eba55562fdfc6059619cee695bd1e8 Mon Sep 17 00:00:00 2001 From: Jose Luis Duran Date: Thu, 28 Aug 2014 02:02:20 +0000 Subject: LaTeX writer: Fix tables - [x] Fix a bug introduced in 66378062b622b0815a1a2ddce5d557e3ad13330c, which causes the table caption to repeat across all pages - [x] Address the issues discussed [here](https://groups.google.com/forum/#!msg/pandoc-discuss/qMu6_5lYy0o/ZAU7lzAIKw0J) regarding the extra vertical space. - [ ] NOTE: This will cause multiline table cells to appear unpadded. See http://tex.stackexchange.com/questions/34971 - [x] Use [`\tabularnewline`](http://tex.stackexchange.com/questions/78796) instead of `\\`. --- tests/tables.latex | 124 +++++++++++++++++++++++++++-------------------------- 1 file changed, 63 insertions(+), 61 deletions(-) (limited to 'tests') diff --git a/tests/tables.latex b/tests/tables.latex index eb665204d..1349960a3 100644 --- a/tests/tables.latex +++ b/tests/tables.latex @@ -1,58 +1,57 @@ Simple table with caption: \begin{longtable}[c]{@{}rlcl@{}} -\caption{Demonstration of simple table syntax.}\\ -\toprule\addlinespace -Right & Left & Center & Default -\\\addlinespace -\midrule\endhead -12 & 12 & 12 & 12 -\\\addlinespace -123 & 123 & 123 & 123 -\\\addlinespace -1 & 1 & 1 & 1 -\\\addlinespace +\caption{Demonstration of simple table syntax.}\tabularnewline +\toprule +Right & Left & Center & Default\tabularnewline +\midrule +\endfirsthead +\toprule +Right & Left & Center & Default\tabularnewline +\midrule +\endhead +12 & 12 & 12 & 12\tabularnewline +123 & 123 & 123 & 123\tabularnewline +1 & 1 & 1 & 1\tabularnewline \bottomrule \end{longtable} Simple table without caption: \begin{longtable}[c]{@{}rlcl@{}} -\toprule\addlinespace -Right & Left & Center & Default -\\\addlinespace -\midrule\endhead -12 & 12 & 12 & 12 -\\\addlinespace -123 & 123 & 123 & 123 -\\\addlinespace -1 & 1 & 1 & 1 -\\\addlinespace +\toprule +Right & Left & Center & Default\tabularnewline +\midrule +\endhead +12 & 12 & 12 & 12\tabularnewline +123 & 123 & 123 & 123\tabularnewline +1 & 1 & 1 & 1\tabularnewline \bottomrule \end{longtable} Simple table indented two spaces: \begin{longtable}[c]{@{}rlcl@{}} -\caption{Demonstration of simple table syntax.}\\ -\toprule\addlinespace -Right & Left & Center & Default -\\\addlinespace -\midrule\endhead -12 & 12 & 12 & 12 -\\\addlinespace -123 & 123 & 123 & 123 -\\\addlinespace -1 & 1 & 1 & 1 -\\\addlinespace +\caption{Demonstration of simple table syntax.}\tabularnewline +\toprule +Right & Left & Center & Default\tabularnewline +\midrule +\endfirsthead +\toprule +Right & Left & Center & Default\tabularnewline +\midrule +\endhead +12 & 12 & 12 & 12\tabularnewline +123 & 123 & 123 & 123\tabularnewline +1 & 1 & 1 & 1\tabularnewline \bottomrule \end{longtable} Multiline table with caption: \begin{longtable}[c]{@{}clrl@{}} -\caption{Here's the caption. It may span multiple lines.}\\ -\toprule\addlinespace +\caption{Here's the caption. It may span multiple lines.}\tabularnewline +\toprule \begin{minipage}[b]{0.13\columnwidth}\centering Centered Header \end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\raggedright @@ -61,9 +60,21 @@ Left Aligned Right Aligned \end{minipage} & \begin{minipage}[b]{0.30\columnwidth}\raggedright Default aligned -\end{minipage} -\\\addlinespace -\midrule\endhead +\end{minipage}\tabularnewline +\midrule +\endfirsthead +\toprule +\begin{minipage}[b]{0.13\columnwidth}\centering +Centered Header +\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\raggedright +Left Aligned +\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedleft +Right Aligned +\end{minipage} & \begin{minipage}[b]{0.30\columnwidth}\raggedright +Default aligned +\end{minipage}\tabularnewline +\midrule +\endhead \begin{minipage}[t]{0.13\columnwidth}\centering First \end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright @@ -72,8 +83,7 @@ row 12.0 \end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright Example of a row that spans multiple lines. -\end{minipage} -\\\addlinespace +\end{minipage}\tabularnewline \begin{minipage}[t]{0.13\columnwidth}\centering Second \end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright @@ -82,15 +92,14 @@ row 5.0 \end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright Here's another one. Note the blank line between rows. -\end{minipage} -\\\addlinespace +\end{minipage}\tabularnewline \bottomrule \end{longtable} Multiline table without caption: \begin{longtable}[c]{@{}clrl@{}} -\toprule\addlinespace +\toprule \begin{minipage}[b]{0.13\columnwidth}\centering Centered Header \end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\raggedright @@ -99,9 +108,9 @@ Left Aligned Right Aligned \end{minipage} & \begin{minipage}[b]{0.30\columnwidth}\raggedright Default aligned -\end{minipage} -\\\addlinespace -\midrule\endhead +\end{minipage}\tabularnewline +\midrule +\endhead \begin{minipage}[t]{0.13\columnwidth}\centering First \end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright @@ -110,8 +119,7 @@ row 12.0 \end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright Example of a row that spans multiple lines. -\end{minipage} -\\\addlinespace +\end{minipage}\tabularnewline \begin{minipage}[t]{0.13\columnwidth}\centering Second \end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright @@ -120,28 +128,24 @@ row 5.0 \end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright Here's another one. Note the blank line between rows. -\end{minipage} -\\\addlinespace +\end{minipage}\tabularnewline \bottomrule \end{longtable} Table without column headers: \begin{longtable}[c]{@{}rlcr@{}} -\toprule\addlinespace -12 & 12 & 12 & 12 -\\\addlinespace -123 & 123 & 123 & 123 -\\\addlinespace -1 & 1 & 1 & 1 -\\\addlinespace +\toprule +12 & 12 & 12 & 12\tabularnewline +123 & 123 & 123 & 123\tabularnewline +1 & 1 & 1 & 1\tabularnewline \bottomrule \end{longtable} Multiline table without column headers: \begin{longtable}[c]{@{}clrl@{}} -\toprule\addlinespace +\toprule \begin{minipage}[t]{0.13\columnwidth}\centering First \end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright @@ -150,8 +154,7 @@ row 12.0 \end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright Example of a row that spans multiple lines. -\end{minipage} -\\\addlinespace +\end{minipage}\tabularnewline \begin{minipage}[t]{0.13\columnwidth}\centering Second \end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright @@ -160,7 +163,6 @@ row 5.0 \end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright Here's another one. Note the blank line between rows. -\end{minipage} -\\\addlinespace +\end{minipage}\tabularnewline \bottomrule \end{longtable} -- cgit v1.2.3 From 4c684561ee0665b014e887ae559b7020e4e9f2d3 Mon Sep 17 00:00:00 2001 From: Jose Luis Duran Date: Fri, 29 Aug 2014 13:54:08 +0000 Subject: LaTeX writer: Add `\strut` to fix multiline tables See: http://tex.stackexchange.com/questions/34971 --- src/Text/Pandoc/Writers/LaTeX.hs | 3 +- tests/tables.latex | 90 ++++++++++++++++++++-------------------- 2 files changed, 47 insertions(+), 46 deletions(-) (limited to 'tests') diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 6c17401d0..b2db7377d 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -556,7 +556,8 @@ tableCellToLaTeX header (width, align, blocks) = do AlignDefault -> "\\raggedright" return $ ("\\begin{minipage}" <> valign <> braces (text (printf "%.2f\\columnwidth" width)) <> - (halign <> cr <> cellContents <> cr) <> "\\end{minipage}") + (halign <> "\\strut" <> cr <> cellContents <> cr) <> + "\\strut\\end{minipage}") $$ case notes of [] -> empty ns -> (case length ns of diff --git a/tests/tables.latex b/tests/tables.latex index 1349960a3..850629499 100644 --- a/tests/tables.latex +++ b/tests/tables.latex @@ -52,47 +52,47 @@ Multiline table with caption: \begin{longtable}[c]{@{}clrl@{}} \caption{Here's the caption. It may span multiple lines.}\tabularnewline \toprule -\begin{minipage}[b]{0.13\columnwidth}\centering +\begin{minipage}[b]{0.13\columnwidth}\centering\strut Centered Header -\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\raggedright +\strut\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\raggedright\strut Left Aligned -\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedleft +\strut\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedleft\strut Right Aligned -\end{minipage} & \begin{minipage}[b]{0.30\columnwidth}\raggedright +\strut\end{minipage} & \begin{minipage}[b]{0.30\columnwidth}\raggedright\strut Default aligned -\end{minipage}\tabularnewline +\strut\end{minipage}\tabularnewline \midrule \endfirsthead \toprule -\begin{minipage}[b]{0.13\columnwidth}\centering +\begin{minipage}[b]{0.13\columnwidth}\centering\strut Centered Header -\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\raggedright +\strut\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\raggedright\strut Left Aligned -\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedleft +\strut\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedleft\strut Right Aligned -\end{minipage} & \begin{minipage}[b]{0.30\columnwidth}\raggedright +\strut\end{minipage} & \begin{minipage}[b]{0.30\columnwidth}\raggedright\strut Default aligned -\end{minipage}\tabularnewline +\strut\end{minipage}\tabularnewline \midrule \endhead -\begin{minipage}[t]{0.13\columnwidth}\centering +\begin{minipage}[t]{0.13\columnwidth}\centering\strut First -\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright +\strut\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright\strut row -\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft +\strut\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft\strut 12.0 -\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright +\strut\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright\strut Example of a row that spans multiple lines. -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.13\columnwidth}\centering +\strut\end{minipage}\tabularnewline +\begin{minipage}[t]{0.13\columnwidth}\centering\strut Second -\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright +\strut\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright\strut row -\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft +\strut\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft\strut 5.0 -\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright +\strut\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright\strut Here's another one. Note the blank line between rows. -\end{minipage}\tabularnewline +\strut\end{minipage}\tabularnewline \bottomrule \end{longtable} @@ -100,35 +100,35 @@ Multiline table without caption: \begin{longtable}[c]{@{}clrl@{}} \toprule -\begin{minipage}[b]{0.13\columnwidth}\centering +\begin{minipage}[b]{0.13\columnwidth}\centering\strut Centered Header -\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\raggedright +\strut\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\raggedright\strut Left Aligned -\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedleft +\strut\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedleft\strut Right Aligned -\end{minipage} & \begin{minipage}[b]{0.30\columnwidth}\raggedright +\strut\end{minipage} & \begin{minipage}[b]{0.30\columnwidth}\raggedright\strut Default aligned -\end{minipage}\tabularnewline +\strut\end{minipage}\tabularnewline \midrule \endhead -\begin{minipage}[t]{0.13\columnwidth}\centering +\begin{minipage}[t]{0.13\columnwidth}\centering\strut First -\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright +\strut\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright\strut row -\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft +\strut\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft\strut 12.0 -\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright +\strut\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright\strut Example of a row that spans multiple lines. -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.13\columnwidth}\centering +\strut\end{minipage}\tabularnewline +\begin{minipage}[t]{0.13\columnwidth}\centering\strut Second -\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright +\strut\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright\strut row -\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft +\strut\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft\strut 5.0 -\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright +\strut\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright\strut Here's another one. Note the blank line between rows. -\end{minipage}\tabularnewline +\strut\end{minipage}\tabularnewline \bottomrule \end{longtable} @@ -146,23 +146,23 @@ Multiline table without column headers: \begin{longtable}[c]{@{}clrl@{}} \toprule -\begin{minipage}[t]{0.13\columnwidth}\centering +\begin{minipage}[t]{0.13\columnwidth}\centering\strut First -\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright +\strut\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright\strut row -\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft +\strut\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft\strut 12.0 -\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright +\strut\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright\strut Example of a row that spans multiple lines. -\end{minipage}\tabularnewline -\begin{minipage}[t]{0.13\columnwidth}\centering +\strut\end{minipage}\tabularnewline +\begin{minipage}[t]{0.13\columnwidth}\centering\strut Second -\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright +\strut\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright\strut row -\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft +\strut\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft\strut 5.0 -\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright +\strut\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright\strut Here's another one. Note the blank line between rows. -\end{minipage}\tabularnewline +\strut\end{minipage}\tabularnewline \bottomrule \end{longtable} -- cgit v1.2.3