diff options
-rw-r--r-- | src/Text/Pandoc/Writers/LaTeX/Table.hs | 13 | ||||
-rw-r--r-- | test/command/5367.md | 8 | ||||
-rw-r--r-- | test/tables.latex | 30 | ||||
-rw-r--r-- | test/tables/nordics.latex | 26 | ||||
-rw-r--r-- | test/tables/planets.latex | 8 | ||||
-rw-r--r-- | test/tables/students.latex | 12 |
6 files changed, 79 insertions, 18 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX/Table.hs b/src/Text/Pandoc/Writers/LaTeX/Table.hs index 16f63314b..8dc7d1162 100644 --- a/src/Text/Pandoc/Writers/LaTeX/Table.hs +++ b/src/Text/Pandoc/Writers/LaTeX/Table.hs @@ -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 diff --git a/test/command/5367.md b/test/command/5367.md index 2d3a5e52e..a67011c2f 100644 --- a/test/command/5367.md +++ b/test/command/5367.md @@ -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} \\ diff --git a/test/tables.latex b/test/tables.latex index afa14d845..9d111fa7a 100644 --- a/test/tables.latex +++ b/test/tables.latex @@ -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. \\ diff --git a/test/tables/nordics.latex b/test/tables/nordics.latex index 1b5929bad..1dcac7319 100644 --- a/test/tables/nordics.latex +++ b/test/tables/nordics.latex @@ -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 \\ diff --git a/test/tables/planets.latex b/test/tables/planets.latex index 8238c43f3..b22c3adeb 100644 --- a/test/tables/planets.latex +++ b/test/tables/planets.latex @@ -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} diff --git a/test/tables/students.latex b/test/tables/students.latex index 87efb0851..3d4d287d9 100644 --- a/test/tables/students.latex +++ b/test/tables/students.latex @@ -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} \\ |