Three pieces of vertical space shape the header block, and they are named here for where they sit rather than for the padding that produces them, because the mapping between the two is not obvious:
Arguments
- x
A clintable object
- above
Space above each header row, in points
- below
Space below each header row, in points. The bottom row's is what sets how far the rule sits from the column labels
- rule_to_body
Space between that rule and the first body row, in points. A single value - there is only one first body row per page
- rows
Which header rows to space, as row numbers counting from the top. The default spaces every row; rows left out keep whatever spacing they already have
Details
aboveis the space over each header row. On a single row header that is the buffer above the column labels; on a spanned header it also opens the space between the levels, which is what a blank row above the header normally looks like.belowis the space under each header row. The one that matters most is the bottom row's, because a cell's bottom border sits at the bottom edge of the cell, below its padding - so this is what decides how far the rule is drawn from the column labels. It does not open space beneath the rule.rule_to_bodyis the space between that rule and the first row of the table body, which is the one that has to come from the body side.
above and below apply to every row of the header by default, which is
the usual convention and matches flextable::padding(part = "header"). A
header row that needs a different gap can be given one either by passing a
value per row - above = c(18, 34) - or by aiming the call at particular
rows with rows, which leaves the others alone. That matters because the
spacing is applied as the table renders, after anything the caller did, so a
call covering every row would otherwise overwrite a per-row
flextable::padding() set beforehand.
rule_to_body is applied to the first row of every page, so a table split
over pages keeps the same gap under the rule throughout. If a group label is
added above the header it keeps its own spacing, since it is put there as
the table renders.
Called a second time, this refines what the first call set rather than replacing it: arguments this call does not name keep their earlier value.
Spacing is given in points, which is what flextable measures cell padding in. Whatever is set here replaces the header padding clinify starts with.
Examples
# A blank row's worth of space around each header row, the rule close under
# the labels, and a little air before the body starts
clintable(mtcars) |>
clin_header_pad(above = 18, below = 4, rule_to_body = 6)
mpg
cyl
disp
hp
drat
wt
qsec
vs
am
gear
carb
21.0
6
160.0
110
3.90
2.620
16.46
0
1
4
4
21.0
6
160.0
110
3.90
2.875
17.02
0
1
4
4
22.8
4
108.0
93
3.85
2.320
18.61
1
1
4
1
21.4
6
258.0
110
3.08
3.215
19.44
1
0
3
1
18.7
8
360.0
175
3.15
3.440
17.02
0
0
3
2
18.1
6
225.0
105
2.76
3.460
20.22
1
0
3
1
14.3
8
360.0
245
3.21
3.570
15.84
0
0
3
4
24.4
4
146.7
62
3.69
3.190
20.00
1
0
4
2
22.8
4
140.8
95
3.92
3.150
22.90
1
0
4
2
19.2
6
167.6
123
3.92
3.440
18.30
1
0
4
4
17.8
6
167.6
123
3.92
3.440
18.90
1
0
4
4
16.4
8
275.8
180
3.07
4.070
17.40
0
0
3
3
17.3
8
275.8
180
3.07
3.730
17.60
0
0
3
3
15.2
8
275.8
180
3.07
3.780
18.00
0
0
3
3
10.4
8
472.0
205
2.93
5.250
17.98
0
0
3
4