[texhax] refart with package float a hack for caption over the float

Ron RJF Fehd ron.fehd.macro.maven at gmail.com
Fri Sep 13 18:36:28 CEST 2013


This was an interesting piece of detective work:
I had to open the \jobname.toc file and squint at it
and wonder what is that trailing argument?

\contentsline {section}{\numberline {1}One}{1}{section.1}

Oh, yeah: that last {section.1} is a hyperlink

The hyperref argument is not in the manual I have: LaTeX Companion, 2e, pg
46,
section 2.3.1 Entering information into the contents files.

Since I could not get the caption on top of the program listing
by using the float package command \floatstyle{plaintop}
I decided to use
\addcontentsline{lop}{section}{...}

That did not work the way I wanted; I eventually got this working.

Ron Fehd  {SAS} macro maven

\documentclass{refart}
\usepackage{float}\newfloat{program}{H}{lop}%[section]
\floatstyle{plaintop}%
% command programCaption
% description: provides movable caption of float named program
% purpose    : package{float} floatstype{plaintop} does not work
% tricks     : 1 add hyperref.hypertarget
%            : 2 add hypertarget reference at end of contentsline
\newcommand\programCaption[1]{%
\stepcounter{program}%
\hypertarget{program.\theprogram}{Program.\theprogram\ #1}%
\addtocontents{lop}{\protect\contentsline{program}%
{\protect\numberline{\theprogram}{\ignorespaces #1}}{\thepage}%
{program.\theprogram}}%this last argument is for hyperref
%\addcontentsline{lop}{section}{#1}%saved for comparison
}%end programCaption
\title{\jobname}\author{R.J. Fehd}\date{draft of \today}
\usepackage{fancyvrb,hyperref}
\begin{document}\maketitle
\section*{Abstract}This document is a demonstration of the
\href{http://www.ctan.org/pkg/float}{Float package} within
\texttt{refart} class showing a hack, kludge or workaround
for a caption of a program that can be moved around.

\tableofcontents
\listof{program}{List of Programs}
\section{One}Some text here.
This sentence is about
\programCaption{Caption is where author puts it.}
\begin{program}
\begin{Verbatim}
/* name: program that does something */
\end{Verbatim}
\end{program}
\newpage
\section{Two}
\programCaption{Caption is wherever the author decides to put it},
followed by more text.

I got this working by comparing the listings of \jobname.toc and
\jobname.lop.

This is the text of the file \jobname.lop.

\begin{program}
\begin{maxipage}
\begin{Verbatim}[fontsize=\footnotesize]
\contentsline {program}{\numberline {1}{\ignorespaces Caption is
...}}{1}{program.1}
\contentsline {program}{\numberline {2}{\ignorespaces Caption ... author
decides}}{2}{program.2}
\end{Verbatim}
\end{maxipage}
\end{program}
\end{document}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/texhax/attachments/20130913/cd4135d4/attachment.html>


More information about the texhax mailing list