Consider adding `\MakeLinkTarget{}` before `\label` for tables
lierdakil opened this issue · 4 comments
Extracted from #402:
Of interest, in my testing over the last few weeks I discovered that with
longtable
if\label
is prefixed with\MakeLinkTarget{}
then the anchor is the same as with regular floats that respect the defaulthypcap=true
option of thecaption
package (loaded bypandoc-crossref
). This macro has been included in thehyperref
package since release7.00o
of 2022-05-15, and is documented inhyperref-linktarget.pdf
. Not sure if you would consider it worthwhile adding that, which I have been using in a lua filter run afterpandoc-crossref
.
With LaTeX output, pandoc-crossref
loads the caption
package, which by default sets the option hypcap=true
, thereby making the anchors of hyperref
package links at the beginning of the (floating) environment, and raised by an amount as determined by the caption
package option hypcapspace
, which has the default value of 0.5\baselineskip
. This results in some whitespace above the target in a PDF viewer e.g:
instead of:
However, this does not work for longtable
environments (i.e. pandoc tables), where the option hypcapspace=0pt
is always in effect. By prefixing the \label
command of pandoc tables with the \MakeLinkTarget{}
command from the hyperref
package. The functionality of the hypcapspace
option effectively also works for longtables, therefore matching the behaviour of all other floats.
Potential drawback: This command was only added to hyperref
in release 7.00o, on 2022-05-15.
Where does \MakeLinkTarget{}
put the actual bookmark? Is it ultimately attached to the float (good) or to the caption (bad)? I'm a bit unclear on how that would interact with \captionsetup[table]{position=bottom}
(or equivalent)
Pandoc tables (i.e. longtable
) are written with the \caption
command placed at the beginning of the environment, above \endfirsthead
(i.e. the start of the table). Currently, it is not possible to change the position of the caption as written by pandoc, and it is unlikely to change either, considering longtable
has the potential for multi-page tables. \captionsetup[table]{position=}
has no effect on where the caption is output, but indicates whether the extra space that separates the caption and, in this case, table should be either above or below the caption. The default of auto
is correct in the case of the standard classes, but say in KOMA-Script
, the \KOMAoptions{captions=abovetable}
option needs to be set. An exception to the above is with floats created by the float
package (e.g. codelisting
), where the position and spacing of the caption is solely determined by the \floatstyle
command.
So, in this case of longtable
, with the caption above the table, \MakeLinkTarget{}
works correctly by raising the link target above the baseline of the caption.
Ah, right, my mistake, as I said, my LaTeX-fu is very rusty. Sounds good. As for the concern about MakeLinkTarget
being rather new, we can just check if the command exists and alias it to noop if it doesn't. I'll see if I can get to it this weekend.