LaTeX writer: Improve table spacing.

+ Remove the `\strut` that was added at the end of minipage
  environments in cells.

+ Replace `\tabularnewline` with `\\ \addlinespace`.

Closes #6842, closes #6860.
This commit is contained in:
John MacFarlane 2020-11-22 10:54:42 -08:00
parent 5344dab8eb
commit b5b5ef92cb
4 changed files with 73 additions and 73 deletions

View file

@ -862,7 +862,7 @@ tableRowToLaTeX header aligns widths cols = do
else widths else widths
let numcols = length widths' let numcols = length widths'
cells <- mapM (tableCellToLaTeX header numcols) $ zip3 widths' aligns cols cells <- mapM (tableCellToLaTeX header numcols) $ zip3 widths' aligns cols
return $ hsep (intersperse "&" cells) <> "\\tabularnewline" return $ hsep (intersperse "&" cells) <> " \\\\ \\addlinespace"
-- For simple latex tables (without minipages or parboxes), -- For simple latex tables (without minipages or parboxes),
-- we need to go to some lengths to get line breaks working: -- we need to go to some lengths to get line breaks working:
@ -914,7 +914,7 @@ tableCellToLaTeX header numcols (width, align, blocks) = do
braces (text (printf braces (text (printf
"(\\columnwidth - %d\\tabcolsep) * \\real{%.2f}" "(\\columnwidth - %d\\tabcolsep) * \\real{%.2f}"
(numcols - 1) width)) <> (numcols - 1) width)) <>
halign <> cr <> cellContents <> "\\strut" <> cr <> halign <> cr <> cellContents <> cr <>
"\\end{minipage}" "\\end{minipage}"
-- (\columnwidth - 8\tabcolsep) * \real{0.15} -- (\columnwidth - 8\tabcolsep) * \real{0.15}

View file

@ -14,14 +14,14 @@ is used.
\begin{longtable}[]{@{}ll@{}} \begin{longtable}[]{@{}ll@{}}
\caption{a table}\tabularnewline \caption{a table}\tabularnewline
\toprule \toprule
x & y\footnote{a footnote}\tabularnewline x & y\footnote{a footnote} \\ \addlinespace
\midrule \midrule
\endfirsthead \endfirsthead
\toprule \toprule
x & y{}\tabularnewline x & y{} \\ \addlinespace
\midrule \midrule
\endhead \endhead
1 & 2\tabularnewline 1 & 2 \\ \addlinespace
\bottomrule \bottomrule
\end{longtable} \end{longtable}
``` ```

View file

@ -24,19 +24,19 @@ hello\footnote{doc footnote}
\caption[Sample table.]{Sample table.\footnote{caption footnote}}\tabularnewline \caption[Sample table.]{Sample table.\footnote{caption footnote}}\tabularnewline
\toprule \toprule
\begin{minipage}[b]{(\columnwidth - 0\tabcolsep) * \real{0.17}}\centering \begin{minipage}[b]{(\columnwidth - 0\tabcolsep) * \real{0.17}}\centering
Fruit\footnote{header footnote}\strut Fruit\footnote{header footnote}
\end{minipage}\tabularnewline \end{minipage} \\ \addlinespace
\midrule \midrule
\endfirsthead \endfirsthead
\toprule \toprule
\begin{minipage}[b]{(\columnwidth - 0\tabcolsep) * \real{0.17}}\centering \begin{minipage}[b]{(\columnwidth - 0\tabcolsep) * \real{0.17}}\centering
Fruit{}\strut Fruit{}
\end{minipage}\tabularnewline \end{minipage} \\ \addlinespace
\midrule \midrule
\endhead \endhead
\begin{minipage}[t]{(\columnwidth - 0\tabcolsep) * \real{0.17}}\centering \begin{minipage}[t]{(\columnwidth - 0\tabcolsep) * \real{0.17}}\centering
Bans\footnote{table cell footnote}\strut Bans\footnote{table cell footnote}
\end{minipage}\tabularnewline \end{minipage} \\ \addlinespace
\bottomrule \bottomrule
\end{longtable} \end{longtable}

View file

@ -3,16 +3,16 @@ Simple table with caption:
\begin{longtable}[]{@{}rlcl@{}} \begin{longtable}[]{@{}rlcl@{}}
\caption{Demonstration of simple table syntax.}\tabularnewline \caption{Demonstration of simple table syntax.}\tabularnewline
\toprule \toprule
Right & Left & Center & Default\tabularnewline Right & Left & Center & Default \\ \addlinespace
\midrule \midrule
\endfirsthead \endfirsthead
\toprule \toprule
Right & Left & Center & Default\tabularnewline Right & Left & Center & Default \\ \addlinespace
\midrule \midrule
\endhead \endhead
12 & 12 & 12 & 12\tabularnewline 12 & 12 & 12 & 12 \\ \addlinespace
123 & 123 & 123 & 123\tabularnewline 123 & 123 & 123 & 123 \\ \addlinespace
1 & 1 & 1 & 1\tabularnewline 1 & 1 & 1 & 1 \\ \addlinespace
\bottomrule \bottomrule
\end{longtable} \end{longtable}
@ -20,12 +20,12 @@ Simple table without caption:
\begin{longtable}[]{@{}rlcl@{}} \begin{longtable}[]{@{}rlcl@{}}
\toprule \toprule
Right & Left & Center & Default\tabularnewline Right & Left & Center & Default \\ \addlinespace
\midrule \midrule
\endhead \endhead
12 & 12 & 12 & 12\tabularnewline 12 & 12 & 12 & 12 \\ \addlinespace
123 & 123 & 123 & 123\tabularnewline 123 & 123 & 123 & 123 \\ \addlinespace
1 & 1 & 1 & 1\tabularnewline 1 & 1 & 1 & 1 \\ \addlinespace
\bottomrule \bottomrule
\end{longtable} \end{longtable}
@ -34,16 +34,16 @@ Simple table indented two spaces:
\begin{longtable}[]{@{}rlcl@{}} \begin{longtable}[]{@{}rlcl@{}}
\caption{Demonstration of simple table syntax.}\tabularnewline \caption{Demonstration of simple table syntax.}\tabularnewline
\toprule \toprule
Right & Left & Center & Default\tabularnewline Right & Left & Center & Default \\ \addlinespace
\midrule \midrule
\endfirsthead \endfirsthead
\toprule \toprule
Right & Left & Center & Default\tabularnewline Right & Left & Center & Default \\ \addlinespace
\midrule \midrule
\endhead \endhead
12 & 12 & 12 & 12\tabularnewline 12 & 12 & 12 & 12 \\ \addlinespace
123 & 123 & 123 & 123\tabularnewline 123 & 123 & 123 & 123 \\ \addlinespace
1 & 1 & 1 & 1\tabularnewline 1 & 1 & 1 & 1 \\ \addlinespace
\bottomrule \bottomrule
\end{longtable} \end{longtable}
@ -53,58 +53,58 @@ Multiline table with caption:
\caption{Here's the caption. It may span multiple lines.}\tabularnewline \caption{Here's the caption. It may span multiple lines.}\tabularnewline
\toprule \toprule
\begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.15}}\centering \begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.15}}\centering
Centered Header\strut Centered Header
\end{minipage} & \end{minipage} &
\begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.14}}\raggedright \begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.14}}\raggedright
Left Aligned\strut Left Aligned
\end{minipage} & \end{minipage} &
\begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.16}}\raggedleft \begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.16}}\raggedleft
Right Aligned\strut Right Aligned
\end{minipage} & \end{minipage} &
\begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.35}}\raggedright \begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.35}}\raggedright
Default aligned\strut Default aligned
\end{minipage}\tabularnewline \end{minipage} \\ \addlinespace
\midrule \midrule
\endfirsthead \endfirsthead
\toprule \toprule
\begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.15}}\centering \begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.15}}\centering
Centered Header\strut Centered Header
\end{minipage} & \end{minipage} &
\begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.14}}\raggedright \begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.14}}\raggedright
Left Aligned\strut Left Aligned
\end{minipage} & \end{minipage} &
\begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.16}}\raggedleft \begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.16}}\raggedleft
Right Aligned\strut Right Aligned
\end{minipage} & \end{minipage} &
\begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.35}}\raggedright \begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.35}}\raggedright
Default aligned\strut Default aligned
\end{minipage}\tabularnewline \end{minipage} \\ \addlinespace
\midrule \midrule
\endhead \endhead
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.15}}\centering \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.15}}\centering
First\strut First
\end{minipage} & \end{minipage} &
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.14}}\raggedright \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.14}}\raggedright
row\strut row
\end{minipage} & \end{minipage} &
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.16}}\raggedleft \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.16}}\raggedleft
12.0\strut 12.0
\end{minipage} & \end{minipage} &
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.35}}\raggedright \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.35}}\raggedright
Example of a row that spans multiple lines.\strut Example of a row that spans multiple lines.
\end{minipage}\tabularnewline \end{minipage} \\ \addlinespace
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.15}}\centering \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.15}}\centering
Second\strut Second
\end{minipage} & \end{minipage} &
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.14}}\raggedright \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.14}}\raggedright
row\strut row
\end{minipage} & \end{minipage} &
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.16}}\raggedleft \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.16}}\raggedleft
5.0\strut 5.0
\end{minipage} & \end{minipage} &
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.35}}\raggedright \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.35}}\raggedright
Here's another one. Note the blank line between rows.\strut Here's another one. Note the blank line between rows.
\end{minipage}\tabularnewline \end{minipage} \\ \addlinespace
\bottomrule \bottomrule
\end{longtable} \end{longtable}
@ -113,43 +113,43 @@ Multiline table without caption:
\begin{longtable}[]{@{}clrl@{}} \begin{longtable}[]{@{}clrl@{}}
\toprule \toprule
\begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.15}}\centering \begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.15}}\centering
Centered Header\strut Centered Header
\end{minipage} & \end{minipage} &
\begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.14}}\raggedright \begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.14}}\raggedright
Left Aligned\strut Left Aligned
\end{minipage} & \end{minipage} &
\begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.16}}\raggedleft \begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.16}}\raggedleft
Right Aligned\strut Right Aligned
\end{minipage} & \end{minipage} &
\begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.35}}\raggedright \begin{minipage}[b]{(\columnwidth - 3\tabcolsep) * \real{0.35}}\raggedright
Default aligned\strut Default aligned
\end{minipage}\tabularnewline \end{minipage} \\ \addlinespace
\midrule \midrule
\endhead \endhead
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.15}}\centering \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.15}}\centering
First\strut First
\end{minipage} & \end{minipage} &
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.14}}\raggedright \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.14}}\raggedright
row\strut row
\end{minipage} & \end{minipage} &
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.16}}\raggedleft \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.16}}\raggedleft
12.0\strut 12.0
\end{minipage} & \end{minipage} &
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.35}}\raggedright \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.35}}\raggedright
Example of a row that spans multiple lines.\strut Example of a row that spans multiple lines.
\end{minipage}\tabularnewline \end{minipage} \\ \addlinespace
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.15}}\centering \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.15}}\centering
Second\strut Second
\end{minipage} & \end{minipage} &
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.14}}\raggedright \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.14}}\raggedright
row\strut row
\end{minipage} & \end{minipage} &
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.16}}\raggedleft \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.16}}\raggedleft
5.0\strut 5.0
\end{minipage} & \end{minipage} &
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.35}}\raggedright \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.35}}\raggedright
Here's another one. Note the blank line between rows.\strut Here's another one. Note the blank line between rows.
\end{minipage}\tabularnewline \end{minipage} \\ \addlinespace
\bottomrule \bottomrule
\end{longtable} \end{longtable}
@ -158,9 +158,9 @@ Table without column headers:
\begin{longtable}[]{@{}rlcr@{}} \begin{longtable}[]{@{}rlcr@{}}
\toprule \toprule
\endhead \endhead
12 & 12 & 12 & 12\tabularnewline 12 & 12 & 12 & 12 \\ \addlinespace
123 & 123 & 123 & 123\tabularnewline 123 & 123 & 123 & 123 \\ \addlinespace
1 & 1 & 1 & 1\tabularnewline 1 & 1 & 1 & 1 \\ \addlinespace
\bottomrule \bottomrule
\end{longtable} \end{longtable}
@ -170,28 +170,28 @@ Multiline table without column headers:
\toprule \toprule
\endhead \endhead
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.15}}\centering \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.15}}\centering
First\strut First
\end{minipage} & \end{minipage} &
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.14}}\raggedright \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.14}}\raggedright
row\strut row
\end{minipage} & \end{minipage} &
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.16}}\raggedleft \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.16}}\raggedleft
12.0\strut 12.0
\end{minipage} & \end{minipage} &
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.35}}\raggedright \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.35}}\raggedright
Example of a row that spans multiple lines.\strut Example of a row that spans multiple lines.
\end{minipage}\tabularnewline \end{minipage} \\ \addlinespace
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.15}}\centering \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.15}}\centering
Second\strut Second
\end{minipage} & \end{minipage} &
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.14}}\raggedright \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.14}}\raggedright
row\strut row
\end{minipage} & \end{minipage} &
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.16}}\raggedleft \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.16}}\raggedleft
5.0\strut 5.0
\end{minipage} & \end{minipage} &
\begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.35}}\raggedright \begin{minipage}[t]{(\columnwidth - 3\tabcolsep) * \real{0.35}}\raggedright
Here's another one. Note the blank line between rows.\strut Here's another one. Note the blank line between rows.
\end{minipage}\tabularnewline \end{minipage} \\ \addlinespace
\bottomrule \bottomrule
\end{longtable} \end{longtable}