Skip to content

Commit 7a82686

Browse files
committed
Use \toprule\noalign{} instead of \toprule() in LaTeX tables.
And similar for `\midrule` and `\bottomrule`. This facilitates redefining `\toprule`, `\midrule`, and `\bottomrule` without needing to gobble the ()s. Closes #8223.
1 parent c4995fe commit 7a82686

File tree

9 files changed

+60
-60
lines changed

9 files changed

+60
-60
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ tableToLaTeX inlnsToLaTeX blksToLaTeX tbl = do
5858
head' <- do
5959
let mkHead = headToLaTeX blksToLaTeX colCount
6060
case (not $ isEmpty capt, not $ isEmptyHead thead) of
61-
(False, False) -> return "\\toprule()"
61+
(False, False) -> return "\\toprule\\noalign{}"
6262
(False, True) -> mkHead thead
63-
(True, False) -> return (capt $$ "\\toprule()" $$ "\\endfirsthead")
63+
(True, False) -> return (capt $$ "\\toprule\\noalign{}" $$ "\\endfirsthead")
6464
(True, True) -> do
6565
-- avoid duplicate notes in head and firsthead:
6666
firsthead <- mkHead thead
@@ -73,7 +73,7 @@ tableToLaTeX inlnsToLaTeX blksToLaTeX tbl = do
7373
else do
7474
lastfoot <- mapM (rowToLaTeX blksToLaTeX colCount BodyCell) $
7575
footRows tfoot
76-
pure $ "\\midrule()" $$ vcat lastfoot
76+
pure $ "\\midrule\\noalign{}" $$ vcat lastfoot
7777
modify $ \s -> s{ stTable = True }
7878
notes <- notesToLaTeX <$> gets stNotes
7979
return
@@ -83,7 +83,7 @@ tableToLaTeX inlnsToLaTeX blksToLaTeX tbl = do
8383
$$ head'
8484
$$ "\\endhead"
8585
$$ foot'
86-
$$ "\\bottomrule()"
86+
$$ "\\bottomrule\\noalign{}"
8787
$$ "\\endlastfoot"
8888
$$ vcat rows'
8989
$$ "\\end{longtable}"
@@ -184,7 +184,7 @@ headToLaTeX blocksWriter colCount (Ann.TableHead _attr headerRows) = do
184184
rowsContents <-
185185
mapM (rowToLaTeX blocksWriter colCount HeaderCell . headerRowCells)
186186
headerRows
187-
return ("\\toprule()" $$ vcat rowsContents $$ "\\midrule()")
187+
return ("\\toprule\\noalign{}" $$ vcat rowsContents $$ "\\midrule\\noalign{}")
188188

189189
-- | Converts a row of table cells into a LaTeX row.
190190
rowToLaTeX :: PandocMonad m

test/command/2378.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ is used.
1313
^D
1414
\begin{longtable}[]{@{}ll@{}}
1515
\caption{a table}\tabularnewline
16-
\toprule()
16+
\toprule\noalign{}
1717
x & y\footnote{a footnote} \\
18-
\midrule()
18+
\midrule\noalign{}
1919
\endfirsthead
20-
\toprule()
20+
\toprule\noalign{}
2121
x & y{} \\
22-
\midrule()
22+
\midrule\noalign{}
2323
\endhead
24-
\bottomrule()
24+
\bottomrule\noalign{}
2525
\endlastfoot
2626
1 & 2 \\
2727
\end{longtable}

test/command/5367.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ hello\footnote{doc footnote}
2323
\begin{longtable}[]{@{}
2424
>{\centering\arraybackslash}p{(\columnwidth - 0\tabcolsep) * \real{0.1667}}@{}}
2525
\caption[Sample table.]{Sample table.\footnote{caption footnote}}\tabularnewline
26-
\toprule()
26+
\toprule\noalign{}
2727
\begin{minipage}[b]{\linewidth}\centering
2828
Fruit\footnote{header footnote}
2929
\end{minipage} \\
30-
\midrule()
30+
\midrule\noalign{}
3131
\endfirsthead
32-
\toprule()
32+
\toprule\noalign{}
3333
\begin{minipage}[b]{\linewidth}\centering
3434
Fruit{}
3535
\end{minipage} \\
36-
\midrule()
36+
\midrule\noalign{}
3737
\endhead
38-
\bottomrule()
38+
\bottomrule\noalign{}
3939
\endlastfoot
4040
Bans\footnote{table cell footnote} \\
4141
\end{longtable}

test/command/7272.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
^D
1717
\begin{longtable}[]{@{}
1818
>{\raggedright\arraybackslash}p{(\columnwidth - 0\tabcolsep) * \real{1.0000}}@{}}
19-
\toprule()
19+
\toprule\noalign{}
2020
\endhead
21-
\bottomrule()
21+
\bottomrule\noalign{}
2222
\endlastfoot
2323
\begin{minipage}[t]{\linewidth}\raggedright
2424
{ text\\

test/command/8219.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
^D
77
\begin{longtable}[]{@{}ll@{}}
88
\caption{}\label{test}\tabularnewline
9-
\toprule()
9+
\toprule\noalign{}
1010
\endfirsthead
1111
\endhead
12-
\bottomrule()
12+
\bottomrule\noalign{}
1313
\endlastfoot
1414
one & two \\
1515
\end{longtable}

test/tables.latex

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ Simple table with caption:
22

33
\begin{longtable}[]{@{}rlcl@{}}
44
\caption{Demonstration of simple table syntax.}\tabularnewline
5-
\toprule()
5+
\toprule\noalign{}
66
Right & Left & Center & Default \\
7-
\midrule()
7+
\midrule\noalign{}
88
\endfirsthead
9-
\toprule()
9+
\toprule\noalign{}
1010
Right & Left & Center & Default \\
11-
\midrule()
11+
\midrule\noalign{}
1212
\endhead
13-
\bottomrule()
13+
\bottomrule\noalign{}
1414
\endlastfoot
1515
12 & 12 & 12 & 12 \\
1616
123 & 123 & 123 & 123 \\
@@ -20,11 +20,11 @@ Right & Left & Center & Default \\
2020
Simple table without caption:
2121

2222
\begin{longtable}[]{@{}rlcl@{}}
23-
\toprule()
23+
\toprule\noalign{}
2424
Right & Left & Center & Default \\
25-
\midrule()
25+
\midrule\noalign{}
2626
\endhead
27-
\bottomrule()
27+
\bottomrule\noalign{}
2828
\endlastfoot
2929
12 & 12 & 12 & 12 \\
3030
123 & 123 & 123 & 123 \\
@@ -35,15 +35,15 @@ Simple table indented two spaces:
3535

3636
\begin{longtable}[]{@{}rlcl@{}}
3737
\caption{Demonstration of simple table syntax.}\tabularnewline
38-
\toprule()
38+
\toprule\noalign{}
3939
Right & Left & Center & Default \\
40-
\midrule()
40+
\midrule\noalign{}
4141
\endfirsthead
42-
\toprule()
42+
\toprule\noalign{}
4343
Right & Left & Center & Default \\
44-
\midrule()
44+
\midrule\noalign{}
4545
\endhead
46-
\bottomrule()
46+
\bottomrule\noalign{}
4747
\endlastfoot
4848
12 & 12 & 12 & 12 \\
4949
123 & 123 & 123 & 123 \\
@@ -58,7 +58,7 @@ Multiline table with caption:
5858
>{\raggedleft\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1625}}
5959
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.3500}}@{}}
6060
\caption{Here's the caption. It may span multiple lines.}\tabularnewline
61-
\toprule()
61+
\toprule\noalign{}
6262
\begin{minipage}[b]{\linewidth}\centering
6363
Centered Header
6464
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
@@ -68,9 +68,9 @@ Right Aligned
6868
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
6969
Default aligned
7070
\end{minipage} \\
71-
\midrule()
71+
\midrule\noalign{}
7272
\endfirsthead
73-
\toprule()
73+
\toprule\noalign{}
7474
\begin{minipage}[b]{\linewidth}\centering
7575
Centered Header
7676
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
@@ -80,9 +80,9 @@ Right Aligned
8080
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
8181
Default aligned
8282
\end{minipage} \\
83-
\midrule()
83+
\midrule\noalign{}
8484
\endhead
85-
\bottomrule()
85+
\bottomrule\noalign{}
8686
\endlastfoot
8787
First & row & 12.0 & Example of a row that spans multiple lines. \\
8888
Second & row & 5.0 & Here's another one. Note the blank line between rows. \\
@@ -95,7 +95,7 @@ Multiline table without caption:
9595
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1375}}
9696
>{\raggedleft\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1625}}
9797
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.3500}}@{}}
98-
\toprule()
98+
\toprule\noalign{}
9999
\begin{minipage}[b]{\linewidth}\centering
100100
Centered Header
101101
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
@@ -105,9 +105,9 @@ Right Aligned
105105
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
106106
Default aligned
107107
\end{minipage} \\
108-
\midrule()
108+
\midrule\noalign{}
109109
\endhead
110-
\bottomrule()
110+
\bottomrule\noalign{}
111111
\endlastfoot
112112
First & row & 12.0 & Example of a row that spans multiple lines. \\
113113
Second & row & 5.0 & Here's another one. Note the blank line between rows. \\
@@ -116,9 +116,9 @@ Second & row & 5.0 & Here's another one. Note the blank line between rows. \\
116116
Table without column headers:
117117

118118
\begin{longtable}[]{@{}rlcr@{}}
119-
\toprule()
119+
\toprule\noalign{}
120120
\endhead
121-
\bottomrule()
121+
\bottomrule\noalign{}
122122
\endlastfoot
123123
12 & 12 & 12 & 12 \\
124124
123 & 123 & 123 & 123 \\
@@ -132,9 +132,9 @@ Multiline table without column headers:
132132
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1375}}
133133
>{\raggedleft\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1625}}
134134
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.3500}}@{}}
135-
\toprule()
135+
\toprule\noalign{}
136136
\endhead
137-
\bottomrule()
137+
\bottomrule\noalign{}
138138
\endlastfoot
139139
First & row & 12.0 & Example of a row that spans multiple lines. \\
140140
Second & row & 5.0 & Here's another one. Note the blank line between rows. \\

test/tables/nordics.latex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2000}}
55
>{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2000}}@{}}
66
\caption{States belonging to the \emph{Nordics.}}\label{nordics}\tabularnewline
7-
\toprule()
7+
\toprule\noalign{}
88
\begin{minipage}[b]{\linewidth}\centering
99
Name
1010
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
@@ -16,9 +16,9 @@ Population\\
1616
Area\\
1717
(in km\textsuperscript{2})\strut
1818
\end{minipage} \\
19-
\midrule()
19+
\midrule\noalign{}
2020
\endfirsthead
21-
\toprule()
21+
\toprule\noalign{}
2222
\begin{minipage}[b]{\linewidth}\centering
2323
Name
2424
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
@@ -30,11 +30,11 @@ Population\\
3030
Area\\
3131
(in km\textsuperscript{2})\strut
3232
\end{minipage} \\
33-
\midrule()
33+
\midrule\noalign{}
3434
\endhead
35-
\midrule()
35+
\midrule\noalign{}
3636
Total & & 27,376,022 & 1,258,336 \\
37-
\bottomrule()
37+
\bottomrule\noalign{}
3838
\endlastfoot
3939
Denmark & Copenhagen & 5,809,502 & 43,094 \\
4040
Finland & Helsinki & 5,537,364 & 338,145 \\

test/tables/planets.latex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
\begin{longtable}[]{@{}cclrrrrrrrrl@{}}
22
\caption{Data about the planets of our solar system.}\tabularnewline
3-
\toprule()
3+
\toprule\noalign{}
44
\multicolumn{2}{@{}>{\centering\arraybackslash}p{(\columnwidth - 22\tabcolsep) * \real{0.0000} + 2\tabcolsep}}{%
55
} & Name & Mass (10\^{}24kg) & Diameter (km) & Density (kg/m\^{}3) & Gravity
66
(m/s\^{}2) & Length of day (hours) & Distance from Sun (10\^{}6km) & Mean
77
temperature (C) & Number of moons & Notes \\
8-
\midrule()
8+
\midrule\noalign{}
99
\endfirsthead
10-
\toprule()
10+
\toprule\noalign{}
1111
\multicolumn{2}{@{}>{\centering\arraybackslash}p{(\columnwidth - 22\tabcolsep) * \real{0.0000} + 2\tabcolsep}}{%
1212
} & Name & Mass (10\^{}24kg) & Diameter (km) & Density (kg/m\^{}3) & Gravity
1313
(m/s\^{}2) & Length of day (hours) & Distance from Sun (10\^{}6km) & Mean
1414
temperature (C) & Number of moons & Notes \\
15-
\midrule()
15+
\midrule\noalign{}
1616
\endhead
17-
\bottomrule()
17+
\bottomrule\noalign{}
1818
\endlastfoot
1919
\multicolumn{2}{@{}>{\centering\arraybackslash}p{(\columnwidth - 22\tabcolsep) * \real{0.0000} + 2\tabcolsep}}{%
2020
\multirow{4}{*}{Terrestrial planets}} & Mercury & 0.330 & 4,879 & 5427 & 3.7 &

test/tables/students.latex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
>{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.5000}}
33
>{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.5000}}@{}}
44
\caption{List of Students}\label{students}\tabularnewline
5-
\toprule()
5+
\toprule\noalign{}
66
\begin{minipage}[b]{\linewidth}\centering
77
Student ID
88
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
99
Name
1010
\end{minipage} \\
11-
\midrule()
11+
\midrule\noalign{}
1212
\endfirsthead
13-
\toprule()
13+
\toprule\noalign{}
1414
\begin{minipage}[b]{\linewidth}\centering
1515
Student ID
1616
\end{minipage} & \begin{minipage}[b]{\linewidth}\centering
1717
Name
1818
\end{minipage} \\
19-
\midrule()
19+
\midrule\noalign{}
2020
\endhead
21-
\bottomrule()
21+
\bottomrule\noalign{}
2222
\endlastfoot
2323
\multicolumn{2}{@{}>{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{1.0000} + 2\tabcolsep}@{}}{%
2424
Computer Science} \\

0 commit comments

Comments
 (0)