LaTeX writer: Fix regression in table header position.
In recent versions the table headers were no longer bottom-aligned (if more than one line). This patch fixes that by using minipages for table headers in non-simple tables. Closes #7347.
This commit is contained in:
parent
c550bf8482
commit
21cc52abe3
6 changed files with 79 additions and 18 deletions
|
@ -16,6 +16,7 @@ module Text.Pandoc.Writers.LaTeX.Table
|
|||
) where
|
||||
import Control.Monad.State.Strict
|
||||
import Data.List (intersperse)
|
||||
import qualified Data.List.NonEmpty as NonEmpty
|
||||
import Data.List.NonEmpty (NonEmpty ((:|)))
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
|
@ -243,8 +244,13 @@ cellToLaTeX :: PandocMonad m
|
|||
-> Ann.Cell
|
||||
-> LW m (Doc Text)
|
||||
cellToLaTeX blockListToLaTeX celltype annotatedCell = do
|
||||
let (Ann.Cell _specs _colnum cell) = annotatedCell
|
||||
let (Cell _attr align rowspan colspan blocks) = cell
|
||||
let (Ann.Cell specs _colnum cell) = annotatedCell
|
||||
let hasWidths = snd (NonEmpty.head specs) /= ColWidthDefault
|
||||
let specAlign = fst (NonEmpty.head specs)
|
||||
let (Cell _attr align' rowspan colspan blocks) = cell
|
||||
let align = case align' of
|
||||
AlignDefault -> specAlign
|
||||
_ -> align'
|
||||
beamer <- gets stBeamer
|
||||
externalNotes <- gets stExternalNotes
|
||||
inMinipage <- gets stInMinipage
|
||||
|
@ -256,7 +262,7 @@ cellToLaTeX blockListToLaTeX celltype annotatedCell = do
|
|||
Plain{} -> True
|
||||
_ -> False
|
||||
result <-
|
||||
if all isPlainOrPara blocks
|
||||
if not hasWidths || (celltype /= HeaderCell && all isPlainOrPara blocks)
|
||||
then
|
||||
blockListToLaTeX $ walk fixLineBreaks $ walk displayMathToInline blocks
|
||||
else do
|
||||
|
@ -290,3 +296,4 @@ cellToLaTeX blockListToLaTeX celltype annotatedCell = do
|
|||
data CellType
|
||||
= HeaderCell
|
||||
| BodyCell
|
||||
deriving Eq
|
||||
|
|
|
@ -24,11 +24,15 @@ hello\footnote{doc footnote}
|
|||
>{\centering\arraybackslash}p{(\columnwidth - 0\tabcolsep) * \real{0.17}}@{}}
|
||||
\caption[Sample table.]{Sample table.\footnote{caption footnote}}\tabularnewline
|
||||
\toprule
|
||||
Fruit\footnote{header footnote} \\
|
||||
\begin{minipage}[b]{\linewidth}\centering
|
||||
Fruit\footnote{header footnote}
|
||||
\end{minipage} \\
|
||||
\midrule
|
||||
\endfirsthead
|
||||
\toprule
|
||||
Fruit{} \\
|
||||
\begin{minipage}[b]{\linewidth}\centering
|
||||
Fruit{}
|
||||
\end{minipage} \\
|
||||
\midrule
|
||||
\endhead
|
||||
Bans\footnote{table cell footnote} \\
|
||||
|
|
|
@ -56,11 +56,27 @@ Multiline table with caption:
|
|||
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.35}}@{}}
|
||||
\caption{Here's the caption. It may span multiple lines.}\tabularnewline
|
||||
\toprule
|
||||
Centered Header & Left Aligned & Right Aligned & Default aligned \\
|
||||
\begin{minipage}[b]{\linewidth}\centering
|
||||
Centered Header
|
||||
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
|
||||
Left Aligned
|
||||
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedleft
|
||||
Right Aligned
|
||||
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
|
||||
Default aligned
|
||||
\end{minipage} \\
|
||||
\midrule
|
||||
\endfirsthead
|
||||
\toprule
|
||||
Centered Header & Left Aligned & Right Aligned & Default aligned \\
|
||||
\begin{minipage}[b]{\linewidth}\centering
|
||||
Centered Header
|
||||
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
|
||||
Left Aligned
|
||||
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedleft
|
||||
Right Aligned
|
||||
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
|
||||
Default aligned
|
||||
\end{minipage} \\
|
||||
\midrule
|
||||
\endhead
|
||||
First & row & 12.0 & Example of a row that spans multiple lines. \\
|
||||
|
@ -76,7 +92,15 @@ Multiline table without caption:
|
|||
>{\raggedleft\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.16}}
|
||||
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.35}}@{}}
|
||||
\toprule
|
||||
Centered Header & Left Aligned & Right Aligned & Default aligned \\
|
||||
\begin{minipage}[b]{\linewidth}\centering
|
||||
Centered Header
|
||||
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
|
||||
Left Aligned
|
||||
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedleft
|
||||
Right Aligned
|
||||
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
|
||||
Default aligned
|
||||
\end{minipage} \\
|
||||
\midrule
|
||||
\endhead
|
||||
First & row & 12.0 & Example of a row that spans multiple lines. \\
|
||||
|
|
|
@ -5,13 +5,31 @@
|
|||
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.20}}@{}}
|
||||
\caption{States belonging to the \emph{Nordics.}}\tabularnewline
|
||||
\toprule
|
||||
Name & Capital & \vtop{\hbox{\strut Population}\hbox{\strut (in 2018)}} &
|
||||
\vtop{\hbox{\strut Area}\hbox{\strut (in km\textsuperscript{2})}} \\
|
||||
\begin{minipage}[b]{\linewidth}\centering
|
||||
Name
|
||||
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
|
||||
Capital
|
||||
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
|
||||
Population\\
|
||||
(in 2018)
|
||||
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
|
||||
Area\\
|
||||
(in km\textsuperscript{2})
|
||||
\end{minipage} \\
|
||||
\midrule
|
||||
\endfirsthead
|
||||
\toprule
|
||||
Name & Capital & \vtop{\hbox{\strut Population}\hbox{\strut (in 2018)}} &
|
||||
\vtop{\hbox{\strut Area}\hbox{\strut (in km\textsuperscript{2})}} \\
|
||||
\begin{minipage}[b]{\linewidth}\centering
|
||||
Name
|
||||
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
|
||||
Capital
|
||||
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
|
||||
Population\\
|
||||
(in 2018)
|
||||
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
|
||||
Area\\
|
||||
(in km\textsuperscript{2})
|
||||
\end{minipage} \\
|
||||
\midrule
|
||||
\endhead
|
||||
Denmark & Copenhagen & 5,809,502 & 43,094 \\
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
\begin{longtable}[]{@{}cclrrrrrrrrl@{}}
|
||||
\caption{Data about the planets of our solar system.}\tabularnewline
|
||||
\toprule
|
||||
\multicolumn{2}{l}{} & Name & Mass (10\^{}24kg) & Diameter (km) & Density
|
||||
\multicolumn{2}{c}{} & Name & Mass (10\^{}24kg) & Diameter (km) & Density
|
||||
(kg/m\^{}3) & Gravity (m/s\^{}2) & Length of day (hours) & Distance from Sun
|
||||
(10\^{}6km) & Mean temperature (C) & Number of moons & Notes \\
|
||||
\midrule
|
||||
\endfirsthead
|
||||
\toprule
|
||||
\multicolumn{2}{l}{} & Name & Mass (10\^{}24kg) & Diameter (km) & Density
|
||||
\multicolumn{2}{c}{} & Name & Mass (10\^{}24kg) & Diameter (km) & Density
|
||||
(kg/m\^{}3) & Gravity (m/s\^{}2) & Length of day (hours) & Distance from Sun
|
||||
(10\^{}6km) & Mean temperature (C) & Number of moons & Notes \\
|
||||
\midrule
|
||||
\endhead
|
||||
\multicolumn{2}{l}{\multirow{4}{*}{Terrestrial planets}} & Mercury & 0.330 &
|
||||
\multicolumn{2}{c}{\multirow{4}{*}{Terrestrial planets}} & Mercury & 0.330 &
|
||||
4,879 & 5427 & 3.7 & 4222.6 & 57.9 & 167 & 0 & Closest to the Sun \\
|
||||
& & Venus & 4.87 & 12,104 & 5243 & 8.9 & 2802.0 & 108.2 & 464 & 0 & \\
|
||||
& & Earth & 5.97 & 12,756 & 5514 & 9.8 & 24.0 & 149.6 & 15 & 1 & Our world \\
|
||||
|
@ -24,7 +24,7 @@ planet \\
|
|||
& \multirow{2}{*}{Ice giants} & Uranus & 86.8 & 51,118 & 1271 & 8.7 & 17.2 &
|
||||
2872.5 & -195 & 27 & \\
|
||||
& & Neptune & 102 & 49,528 & 1638 & 11.0 & 16.1 & 4495.1 & -200 & 14 & \\
|
||||
\multicolumn{2}{l}{Dwarf planets} & Pluto & 0.0146 & 2,370 & 2095 & 0.7 &
|
||||
\multicolumn{2}{c}{Dwarf planets} & Pluto & 0.0146 & 2,370 & 2095 & 0.7 &
|
||||
153.3 & 5906.4 & -225 & 5 & Declassified as a planet in 2006. \\
|
||||
\bottomrule
|
||||
\end{longtable}
|
||||
|
|
|
@ -3,11 +3,19 @@
|
|||
>{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.50}}@{}}
|
||||
\caption{List of Students}\tabularnewline
|
||||
\toprule
|
||||
Student ID & Name \\
|
||||
\begin{minipage}[b]{\linewidth}\centering
|
||||
Student ID
|
||||
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
|
||||
Name
|
||||
\end{minipage} \\
|
||||
\midrule
|
||||
\endfirsthead
|
||||
\toprule
|
||||
Student ID & Name \\
|
||||
\begin{minipage}[b]{\linewidth}\centering
|
||||
Student ID
|
||||
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
|
||||
Name
|
||||
\end{minipage} \\
|
||||
\midrule
|
||||
\endhead
|
||||
\multicolumn{2}{l}{Computer Science} \\
|
||||
|
|
Loading…
Reference in a new issue