git.iko.soy/typeable/pandoc
on master help sign in
Merge branch 'ugly-tables' of https://github.com/jlduran/pandoc into jlduran-ugly-tables
commit017d44af1de0cb037f95b57ec306cd6b9dd9c3fe authorJohn MacFarlane <jgm@berkeley.edu> dateFri 29 Aug 2014, 21:24 (12 years ago) parent608e4024c68456
2 files changed+108−98
src/Text/Pandoc/Writers/LaTeX.hs+13−5 tests/tables.latex+95−93
src/Text/Pandoc/Writers/LaTeX.hs+13−5
@@ -471,12 +471,18 @@ blockToLaTeX (Header level (id',classes,_) lst) =
471471blockToLaTeX (Table caption aligns widths heads rows) = do
472472 headers <- if all null heads
473473 then return empty
474− else ($$ "\\midrule\\endhead") `fmap`
474+ else ($$ "\\midrule\n") `fmap`
475475 (tableRowToLaTeX True aligns widths) heads
476+ let endhead = if all null heads
477+ then empty
478+ else text "\\endhead"
476479 captionText <- inlineListToLaTeX caption
477480 let capt = if isEmpty captionText
478481 then empty
479− else text "\\caption" <> braces captionText <> "\\\\"
482+ else text "\\caption" <> braces captionText
483+ <> "\\tabularnewline\n\\toprule\n"
484+ <> headers
485+ <> "\\endfirsthead"
480486 rows' <- mapM (tableRowToLaTeX False aligns widths) rows
481487 let colDescriptors = text $ concat $ map toColDescriptor aligns
482488 modify $ \s -> s{ stTable = True }
@@ -484,8 +490,9 @@ blockToLaTeX (Table caption aligns widths heads rows) = do
484490 braces ("@{}" <> colDescriptors <> "@{}")
485491 -- the @{} removes extra space at beginning and end
486492 $$ capt
487− $$ "\\toprule\\addlinespace"
493+ $$ "\\toprule"
488494 $$ headers
495+ $$ endhead
489496 $$ vcat rows'
490497 $$ "\\bottomrule"
491498 $$ "\\end{longtable}"
@@ -512,7 +519,7 @@ tableRowToLaTeX header aligns widths cols = do
512519 let scaleFactor = 0.97 ** fromIntegral (length aligns)
513520 let widths' = map (scaleFactor *) widths
514521 cells <- mapM (tableCellToLaTeX header) $ zip3 widths' aligns cols
515− return $ hsep (intersperse "&" cells) $$ "\\\\\\addlinespace"
522+ return $ hsep (intersperse "&" cells) <> "\\tabularnewline"
516523
517524-- For simple latex tables (without minipages or parboxes),
518525-- we need to go to some lengths to get line breaks working:
@@ -549,7 +556,8 @@ tableCellToLaTeX header (width, align, blocks) = do
549556 AlignDefault -> "\\raggedright"
550557 return $ ("\\begin{minipage}" <> valign <>
551558 braces (text (printf "%.2f\\columnwidth" width)) <>
552− (halign <> cr <> cellContents <> cr) <> "\\end{minipage}")
559+ (halign <> "\\strut" <> cr <> cellContents <> cr) <>
560+ "\\strut\\end{minipage}")
553561 $$ case notes of
554562 [] -> empty
555563 ns -> (case length ns of
tests/tables.latex+95−93
@@ -1,166 +1,168 @@
11Simple table with caption:
22
33\begin{longtable}[c]{@{}rlcl@{}}
4−\caption{Demonstration of simple table syntax.}\\
5−\toprule\addlinespace
6−Right & Left & Center & Default
7−\\\addlinespace
8−\midrule\endhead
9−12 & 12 & 12 & 12
10−\\\addlinespace
11−123 & 123 & 123 & 123
12−\\\addlinespace
13−1 & 1 & 1 & 1
14−\\\addlinespace
4+\caption{Demonstration of simple table syntax.}\tabularnewline
5+\toprule
6+Right & Left & Center & Default\tabularnewline
7+\midrule
8+\endfirsthead
9+\toprule
10+Right & Left & Center & Default\tabularnewline
11+\midrule
12+\endhead
13+12 & 12 & 12 & 12\tabularnewline
14+123 & 123 & 123 & 123\tabularnewline
15+1 & 1 & 1 & 1\tabularnewline
1516\bottomrule
1617\end{longtable}
1718
1819Simple table without caption:
1920
2021\begin{longtable}[c]{@{}rlcl@{}}
21−\toprule\addlinespace
22−Right & Left & Center & Default
23−\\\addlinespace
24−\midrule\endhead
25−12 & 12 & 12 & 12
26−\\\addlinespace
27−123 & 123 & 123 & 123
28−\\\addlinespace
29−1 & 1 & 1 & 1
30−\\\addlinespace
22+\toprule
23+Right & Left & Center & Default\tabularnewline
24+\midrule
25+\endhead
26+12 & 12 & 12 & 12\tabularnewline
27+123 & 123 & 123 & 123\tabularnewline
28+1 & 1 & 1 & 1\tabularnewline
3129\bottomrule
3230\end{longtable}
3331
3432Simple table indented two spaces:
3533
3634\begin{longtable}[c]{@{}rlcl@{}}
37−\caption{Demonstration of simple table syntax.}\\
38−\toprule\addlinespace
39−Right & Left & Center & Default
40−\\\addlinespace
41−\midrule\endhead
42−12 & 12 & 12 & 12
43−\\\addlinespace
44−123 & 123 & 123 & 123
45−\\\addlinespace
46−1 & 1 & 1 & 1
47−\\\addlinespace
35+\caption{Demonstration of simple table syntax.}\tabularnewline
36+\toprule
37+Right & Left & Center & Default\tabularnewline
38+\midrule
39+\endfirsthead
40+\toprule
41+Right & Left & Center & Default\tabularnewline
42+\midrule
43+\endhead
44+12 & 12 & 12 & 12\tabularnewline
45+123 & 123 & 123 & 123\tabularnewline
46+1 & 1 & 1 & 1\tabularnewline
4847\bottomrule
4948\end{longtable}
5049
5150Multiline table with caption:
5251
5352\begin{longtable}[c]{@{}clrl@{}}
54−\caption{Here's the caption. It may span multiple lines.}\\
55−\toprule\addlinespace
56−\begin{minipage}[b]{0.13\columnwidth}\centering
53+\caption{Here's the caption. It may span multiple lines.}\tabularnewline
54+\toprule
55+\begin{minipage}[b]{0.13\columnwidth}\centering\strut
5756Centered Header
58−\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\raggedright
57+\strut\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\raggedright\strut
5958Left Aligned
60−\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedleft
59+\strut\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedleft\strut
6160Right Aligned
62−\end{minipage} & \begin{minipage}[b]{0.30\columnwidth}\raggedright
61+\strut\end{minipage} & \begin{minipage}[b]{0.30\columnwidth}\raggedright\strut
6362Default aligned
64−\end{minipage}
65−\\\addlinespace
66−\midrule\endhead
67−\begin{minipage}[t]{0.13\columnwidth}\centering
63+\strut\end{minipage}\tabularnewline
64+\midrule
65+\endfirsthead
66+\toprule
67+\begin{minipage}[b]{0.13\columnwidth}\centering\strut
68+Centered Header
69+\strut\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\raggedright\strut
70+Left Aligned
71+\strut\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedleft\strut
72+Right Aligned
73+\strut\end{minipage} & \begin{minipage}[b]{0.30\columnwidth}\raggedright\strut
74+Default aligned
75+\strut\end{minipage}\tabularnewline
76+\midrule
77+\endhead
78+\begin{minipage}[t]{0.13\columnwidth}\centering\strut
6879First
69−\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright
80+\strut\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright\strut
7081row
71−\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft
82+\strut\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft\strut
728312.0
73−\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright
84+\strut\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright\strut
7485Example of a row that spans multiple lines.
75−\end{minipage}
76−\\\addlinespace
77−\begin{minipage}[t]{0.13\columnwidth}\centering
86+\strut\end{minipage}\tabularnewline
87+\begin{minipage}[t]{0.13\columnwidth}\centering\strut
7888Second
79−\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright
89+\strut\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright\strut
8090row
81−\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft
91+\strut\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft\strut
82925.0
83−\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright
93+\strut\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright\strut
8494Here's another one. Note the blank line between rows.
85−\end{minipage}
86−\\\addlinespace
95+\strut\end{minipage}\tabularnewline
8796\bottomrule
8897\end{longtable}
8998
9099Multiline table without caption:
91100
92101\begin{longtable}[c]{@{}clrl@{}}
93−\toprule\addlinespace
94−\begin{minipage}[b]{0.13\columnwidth}\centering
102+\toprule
103+\begin{minipage}[b]{0.13\columnwidth}\centering\strut
95104Centered Header
96−\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\raggedright
105+\strut\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\raggedright\strut
97106Left Aligned
98−\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedleft
107+\strut\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedleft\strut
99108Right Aligned
100−\end{minipage} & \begin{minipage}[b]{0.30\columnwidth}\raggedright
109+\strut\end{minipage} & \begin{minipage}[b]{0.30\columnwidth}\raggedright\strut
101110Default aligned
102−\end{minipage}
103−\\\addlinespace
104−\midrule\endhead
105−\begin{minipage}[t]{0.13\columnwidth}\centering
111+\strut\end{minipage}\tabularnewline
112+\midrule
113+\endhead
114+\begin{minipage}[t]{0.13\columnwidth}\centering\strut
106115First
107−\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright
116+\strut\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright\strut
108117row
109−\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft
118+\strut\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft\strut
11011912.0
111−\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright
120+\strut\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright\strut
112121Example of a row that spans multiple lines.
113−\end{minipage}
114−\\\addlinespace
115−\begin{minipage}[t]{0.13\columnwidth}\centering
122+\strut\end{minipage}\tabularnewline
123+\begin{minipage}[t]{0.13\columnwidth}\centering\strut
116124Second
117−\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright
125+\strut\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright\strut
118126row
119−\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft
127+\strut\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft\strut
1201285.0
121−\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright
129+\strut\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright\strut
122130Here's another one. Note the blank line between rows.
123−\end{minipage}
124−\\\addlinespace
131+\strut\end{minipage}\tabularnewline
125132\bottomrule
126133\end{longtable}
127134
128135Table without column headers:
129136
130137\begin{longtable}[c]{@{}rlcr@{}}
131−\toprule\addlinespace
132−12 & 12 & 12 & 12
133−\\\addlinespace
134−123 & 123 & 123 & 123
135−\\\addlinespace
136−1 & 1 & 1 & 1
137−\\\addlinespace
138+\toprule
139+12 & 12 & 12 & 12\tabularnewline
140+123 & 123 & 123 & 123\tabularnewline
141+1 & 1 & 1 & 1\tabularnewline
138142\bottomrule
139143\end{longtable}
140144
141145Multiline table without column headers:
142146
143147\begin{longtable}[c]{@{}clrl@{}}
144−\toprule\addlinespace
145−\begin{minipage}[t]{0.13\columnwidth}\centering
148+\toprule
149+\begin{minipage}[t]{0.13\columnwidth}\centering\strut
146150First
147−\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright
151+\strut\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright\strut
148152row
149−\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft
153+\strut\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft\strut
15015412.0
151−\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright
155+\strut\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright\strut
152156Example of a row that spans multiple lines.
153−\end{minipage}
154−\\\addlinespace
155−\begin{minipage}[t]{0.13\columnwidth}\centering
157+\strut\end{minipage}\tabularnewline
158+\begin{minipage}[t]{0.13\columnwidth}\centering\strut
156159Second
157−\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright
160+\strut\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright\strut
158161row
159−\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft
162+\strut\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft\strut
1601635.0
161−\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright
164+\strut\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright\strut
162165Here's another one. Note the blank line between rows.
163−\end{minipage}
164−\\\addlinespace
166+\strut\end{minipage}\tabularnewline
165167\bottomrule
166168\end{longtable}