Fix missing top or right border in LaTeX output #337
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi David, thank you for creating this great package.
I recently use flextable in
bookdown
to format and display some complex tables.And in some cases the LaTeX output is missing some table borders,
either when a merged cell occurs on the rightmost side of a table, or when the header is deleted.
I think issue #329 and #176 also report similar problems.
After digging into the source code, I found that there may be something wrong with the
augment_(top_)borders
function.For example, when
augment_borders
function computes if a right border should be emitted,it checks whether the
col_id
matches thecol_id
of the rightmost column,this is ok for ordinary cells, but not the case for merged ones.
Instead, we can take
rowspan
into consideration and check ifnumeric_col_id + rowspan == no._of_columns + 1
.Also, when this function emits top border (
hhline
),it checks if
ft_row_id
is 1 and if thepart
is the first of all three table parts (which is alwaysheader
).So when the table header is deleted, no top border will be produced.
And we can change its behavior to check if
part
is the first of existing table parts (it'sbody
in caseheader
is missing).As to the coding style, I'm new to R lang, and I think there may be better ways to express these checks.
Please feel free to correct the code if you have better ideas. :-)