git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: Put table captions above tables.
6637806John MacFarlane
src/Text/Pandoc/Writers/LaTeX.hs+2−3
@@ -471,19 +471,18 @@ blockToLaTeX (Table caption aligns widths heads rows) = do
471 captionText <- inlineListToLaTeX caption
471 captionText <- inlineListToLaTeX caption
472 let capt = if isEmpty captionText
472 let capt = if isEmpty captionText
473 then empty
473 then empty
474− else text "\\addlinespace"
475− $$ text "\\caption" <> braces captionText
474+ else text "\\caption" <> braces captionText <> "\\\\"
476 rows' <- mapM (tableRowToLaTeX False aligns widths) rows
475 rows' <- mapM (tableRowToLaTeX False aligns widths) rows
477 let colDescriptors = text $ concat $ map toColDescriptor aligns
476 let colDescriptors = text $ concat $ map toColDescriptor aligns
478 modify $ \s -> s{ stTable = True }
477 modify $ \s -> s{ stTable = True }
479 return $ "\\begin{longtable}[c]" <>
478 return $ "\\begin{longtable}[c]" <>
480 braces ("@{}" <> colDescriptors <> "@{}")
479 braces ("@{}" <> colDescriptors <> "@{}")
481 -- the @{} removes extra space at beginning and end
480 -- the @{} removes extra space at beginning and end
481+ $$ capt
482 $$ "\\toprule\\addlinespace"
482 $$ "\\toprule\\addlinespace"
483 $$ headers
483 $$ headers
484 $$ vcat rows'
484 $$ vcat rows'
485 $$ "\\bottomrule"
485 $$ "\\bottomrule"
486− $$ capt
487 $$ "\\end{longtable}"
486 $$ "\\end{longtable}"
488
487
489toColDescriptor :: Alignment -> String
488toColDescriptor :: Alignment -> String
tests/tables.latex+3−6
@@ -1,6 +1,7 @@
1Simple table with caption:
1Simple table with caption:
2
2
3\begin{longtable}[c]{@{}rlcl@{}}
3\begin{longtable}[c]{@{}rlcl@{}}
4+\caption{Demonstration of simple table syntax.}\\
4\toprule\addlinespace
5\toprule\addlinespace
5Right & Left & Center & Default
6Right & Left & Center & Default
6\\\addlinespace
7\\\addlinespace
@@ -12,8 +13,6 @@ Right & Left & Center & Default
121 & 1 & 1 & 1
131 & 1 & 1 & 1
13\\\addlinespace
14\\\addlinespace
14\bottomrule
15\bottomrule
15−\addlinespace
16−\caption{Demonstration of simple table syntax.}
17\end{longtable}
16\end{longtable}
18
17
19Simple table without caption:
18Simple table without caption:
@@ -35,6 +34,7 @@ Right & Left & Center & Default
35Simple table indented two spaces:
34Simple table indented two spaces:
36
35
37\begin{longtable}[c]{@{}rlcl@{}}
36\begin{longtable}[c]{@{}rlcl@{}}
37+\caption{Demonstration of simple table syntax.}\\
38\toprule\addlinespace
38\toprule\addlinespace
39Right & Left & Center & Default
39Right & Left & Center & Default
40\\\addlinespace
40\\\addlinespace
@@ -46,13 +46,12 @@ Right & Left & Center & Default
461 & 1 & 1 & 1
461 & 1 & 1 & 1
47\\\addlinespace
47\\\addlinespace
48\bottomrule
48\bottomrule
49−\addlinespace
50−\caption{Demonstration of simple table syntax.}
51\end{longtable}
49\end{longtable}
52
50
53Multiline table with caption:
51Multiline table with caption:
54
52
55\begin{longtable}[c]{@{}clrl@{}}
53\begin{longtable}[c]{@{}clrl@{}}
54+\caption{Here's the caption. It may span multiple lines.}\\
56\toprule\addlinespace
55\toprule\addlinespace
57\begin{minipage}[b]{0.13\columnwidth}\centering
56\begin{minipage}[b]{0.13\columnwidth}\centering
58Centered Header
57Centered Header
@@ -86,8 +85,6 @@ Here's another one. Note the blank line between rows.
86\end{minipage}
85\end{minipage}
87\\\addlinespace
86\\\addlinespace
88\bottomrule
87\bottomrule
89−\addlinespace
90−\caption{Here's the caption. It may span multiple lines.}
91\end{longtable}
88\end{longtable}
92
89
93Multiline table without caption:
90Multiline table without caption: