I would like to insert a hyperlink or two for each heading and I would like to have them inserted into the margin such that they are aligned with the header. I was hoping to create a command which would do this automatically, but this is proving to be harder than I expected.
So to begin with, I simply had
\documentclass{article}
\usepackage{marginnote}
\newcommand\Hlink[1]{%
\marginnote{#1}[-1.9\baselineskip]%
\noindent}
\reversemarginpar
\begin{document}
\section{Section 1}
\Hlink{Sec 1 Link}
Lorem Ipsum
\subsection{Subsection 1.1}
\Hlink{Subsec 2 Link}
Lorem Ipsum
\end{document}
Where the -1.9\baselineskip
was chosen by trial and error, but this no longer works for other headings (e.g. \subsection
). Is there a command which defines the spacing after a heading?
The \noindent
preserves the un-indented paragraph, but requires that no lines separate \Hlink
and the start of the text. Though this is a relatively minor issue, surely there is a way around it.
This command has the additional problem that if the header is near the end of a page, it will most most likely cause a page break. I have tried inserting \nobreak
before and after the command, but to no avail.
An additional problem with this is that the margin changes sides depending on the page, though in print it probably looks better, in a PDF this may not be desirable (and the links are meant to be hyperlinks). Is it possible to modify \Hlink
to always use the left side?
\@section
to make it take another optional argument – cmhughes Mar 7 '13 at 5:33\@section
? I have never done such hacking in LaTeX. – JP-Ellis Mar 7 '13 at 6:59