Skip to content

Commit

Permalink
LaTeX writer: Put table captions above tables.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgm committed Jul 10, 2014
1 parent 7d6da11 commit 6637806
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/Text/Pandoc/Writers/LaTeX.hs
Original file line number Diff line number Diff line change
Expand Up @@ -471,19 +471,18 @@ blockToLaTeX (Table caption aligns widths heads rows) = do
captionText <- inlineListToLaTeX caption
let capt = if isEmpty captionText
then empty
else text "\\addlinespace"
$$ text "\\caption" <> braces captionText
else text "\\caption" <> braces captionText <> "\\\\"
rows' <- mapM (tableRowToLaTeX False aligns widths) rows
let colDescriptors = text $ concat $ map toColDescriptor aligns
modify $ \s -> s{ stTable = True }
return $ "\\begin{longtable}[c]" <>
braces ("@{}" <> colDescriptors <> "@{}")
-- the @{} removes extra space at beginning and end
$$ capt
$$ "\\toprule\\addlinespace"
$$ headers
$$ vcat rows'
$$ "\\bottomrule"
$$ capt
$$ "\\end{longtable}"

toColDescriptor :: Alignment -> String
Expand Down
9 changes: 3 additions & 6 deletions tests/tables.latex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Simple table with caption:

\begin{longtable}[c]{@{}rlcl@{}}
\caption{Demonstration of simple table syntax.}\\
\toprule\addlinespace
Right & Left & Center & Default
\\\addlinespace
Expand All @@ -12,8 +13,6 @@ Right & Left & Center & Default
1 & 1 & 1 & 1
\\\addlinespace
\bottomrule
\addlinespace
\caption{Demonstration of simple table syntax.}
\end{longtable}

Simple table without caption:
Expand All @@ -35,6 +34,7 @@ Right & Left & Center & Default
Simple table indented two spaces:

\begin{longtable}[c]{@{}rlcl@{}}
\caption{Demonstration of simple table syntax.}\\
\toprule\addlinespace
Right & Left & Center & Default
\\\addlinespace
Expand All @@ -46,13 +46,12 @@ Right & Left & Center & Default
1 & 1 & 1 & 1
\\\addlinespace
\bottomrule
\addlinespace
\caption{Demonstration of simple table syntax.}
\end{longtable}

Multiline table with caption:

\begin{longtable}[c]{@{}clrl@{}}
\caption{Here's the caption. It may span multiple lines.}\\
\toprule\addlinespace
\begin{minipage}[b]{0.13\columnwidth}\centering
Centered Header
Expand Down Expand Up @@ -86,8 +85,6 @@ Here's another one. Note the blank line between rows.
\end{minipage}
\\\addlinespace
\bottomrule
\addlinespace
\caption{Here's the caption. It may span multiple lines.}
\end{longtable}

Multiline table without caption:
Expand Down

0 comments on commit 6637806

Please sign in to comment.