Skip to content

Commit c2482b9

Browse files
committed
LaTeX writer: make alignment work within multirow in tables.
Closes #10772.
1 parent c589a89 commit c2482b9

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/Text/Pandoc/Writers/LaTeX/Table.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ cellToLaTeX blockListToLaTeX isSimpleTable colCount celltype annotatedCell = do
367367
<> braces ("%\n" <> x)
368368
-- linebreak for readability
369369
let hasColWidths = not (all (== ColWidthDefault) colWidths)
370+
let aligncmd = case specAlign of
371+
AlignCenter -> "\\centering\\arraybackslash "
372+
AlignRight -> "\\raggedright\\arraybackslash "
373+
_ -> mempty
370374
let inMultiRow x = case rowspan of
371375
(RowSpan 1) -> x
372376
(RowSpan n) -> let nrows = literal (tshow n)
@@ -375,7 +379,7 @@ cellToLaTeX blockListToLaTeX isSimpleTable colCount celltype annotatedCell = do
375379
(if hasColWidths
376380
then "=" -- max width
377381
else "*") -- natural width
378-
<> braces x
382+
<> braces (aligncmd <> x)
379383
return . inMultiColumn . inMultiRow $ result
380384

381385
-- | Returns the width of a cell spanning @n@ columns.

test/tables/planets.latex

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ temperature (C) & Number of moons & Notes \\
1717
\bottomrule\noalign{}
1818
\endlastfoot
1919
\multicolumn{2}{@{}c}{%
20-
\multirow{4}{*}{Terrestrial planets}} & Mercury & 0.330 & 4,879 & 5427 & 3.7 &
21-
4222.6 & 57.9 & 167 & 0 & Closest to the Sun \\
20+
\multirow{4}{*}{\centering\arraybackslash Terrestrial planets}} & Mercury &
21+
0.330 & 4,879 & 5427 & 3.7 & 4222.6 & 57.9 & 167 & 0 & Closest to the Sun \\
2222
& & Venus & 4.87 & 12,104 & 5243 & 8.9 & 2802.0 & 108.2 & 464 & 0 & \\
2323
& & Earth & 5.97 & 12,756 & 5514 & 9.8 & 24.0 & 149.6 & 15 & 1 & Our world \\
2424
& & Mars & 0.642 & 6,792 & 3933 & 3.7 & 24.7 & 227.9 & -65 & 2 & The red
2525
planet \\
26-
\multirow{4}{*}{Jovian planets} & \multirow{2}{*}{Gas giants} & Jupiter & 1898 &
27-
142,984 & 1326 & 23.1 & 9.9 & 778.6 & -110 & 67 & The largest planet \\
26+
\multirow{4}{*}{\centering\arraybackslash Jovian planets} &
27+
\multirow{2}{*}{\centering\arraybackslash Gas giants} & Jupiter & 1898 & 142,984
28+
& 1326 & 23.1 & 9.9 & 778.6 & -110 & 67 & The largest planet \\
2829
& & Saturn & 568 & 120,536 & 687 & 9.0 & 10.7 & 1433.5 & -140 & 62 & \\
29-
& \multirow{2}{*}{Ice giants} & Uranus & 86.8 & 51,118 & 1271 & 8.7 & 17.2 &
30-
2872.5 & -195 & 27 & \\
30+
& \multirow{2}{*}{\centering\arraybackslash Ice giants} & Uranus & 86.8 & 51,118
31+
& 1271 & 8.7 & 17.2 & 2872.5 & -195 & 27 & \\
3132
& & Neptune & 102 & 49,528 & 1638 & 11.0 & 16.1 & 4495.1 & -200 & 14 & \\
3233
\multicolumn{2}{@{}c}{%
3334
Dwarf planets} & Pluto & 0.0146 & 2,370 & 2095 & 0.7 & 153.3 & 5906.4 & -225 & 5

0 commit comments

Comments
 (0)