# newcommand for hvfloat

Using the hvfloat package:

\documentclass[pdftex,10pt,b5paper,twoside]{report}
\usepackage[showframe,lmargin=25mm,rmargin=25mm,tmargin=27mm,bmargin=30mm]{geometry}
\usepackage[demo]{graphicx}
\usepackage{hvfloat}

\begin{document}

\appendix
\chapter{Test chapter}

\hvFloat[%
floatPos=htb,%
capVPos=c,%
rotAngle=90,
objectPos=c]{figure}{\includegraphics[width=353pt,height=290pt]{image}}%
[Commercial crude oil inventories, SPX excess returns, S\&P GCSI excess return time series]{Commercial crude oil inventories calculated as the logarithm of the current value divided by the mean of same weekly values over the past 5 years, Log excess returns on the S\&P Goldman Sachs Commodity Index,  Log excess returns on the S\&P 500 index.}{fig:test}

\end{document}


can I in any way write a function that automatically rotate the "object" (rotAngle), depending on if the figure is on a even or odd page:

Have tried:

\usepackage{ifthen}
\newcommand{\currentside}{\ifthenelse{\isodd{\thepage}}{270}{90}}

rotAngle = \currentside


But can't get i to work.. Anyone have a suggestion?

-
the command you created refers to the value of rotAngle, right? (because the value you're using for objectPos is c) –  henrique Jun 6 '11 at 23:27
@henrique: true. any suggestion? –  latexmp Jun 6 '11 at 23:32
i'm working on it :) –  henrique Jun 6 '11 at 23:54

Define a special key which then takes the label of the image into account with \pageref{..}

\documentclass[b5paper,twoside]{report}
\usepackage[showframe,lmargin=25mm,rmargin=25mm,tmargin=27mm,bmargin=30mm]{geometry}
\usepackage[demo]{graphicx}
\usepackage{hvfloat}
\makeatletter
\define@key{hvSet}{RotAngle}[]{%
\ifx\relax#1\relax\def\hvSet@rotAngle{90}\else
\ifodd\pageref{#1}\def\hvSet@rotAngle{90}\else\def\hvSet@rotAngle{270}\fi\fi}
\makeatother

\begin{document}

\appendix
\chapter{Test chapter}

\hvFloat[%
floatPos=htb,%
capVPos=c,%
RotAngle=fig:test,
objectPos=c]{figure}{\includegraphics[width=300pt,height=290pt]{image}}%
[Commercial crude oil inventories, SPX excess returns, S\&P GCSI excess return time series]{Commercial crude oil inventories calculated as the logarithm of the current value divided by the mean of same weekly values over the past 5 years, Log excess returns on the S\&P Goldman Sachs Commodity Index,  Log excess returns on the S\&P 500 index.}{fig:test}

\clearpage

\hvFloat[
floatPos=htb,
capVPos=c,
RotAngle=fig:testA,
objectPos=c]{figure}{\includegraphics[width=353pt,height=290pt]{image}}%
[Commercial crude oil inventories, SPX excess returns, S\&P GCSI excess return time series]{Commercial crude oil inventories calculated as the logarithm of the current value divided by the mean of same weekly values over the past 5 years, Log excess returns on the S\&P Goldman Sachs Commodity Index,  Log excess returns on the S\&P 500 index.}{fig:testA}

\clearpage

\hvFloat[
floatPos=htb,
capVPos=c,
RotAngle=,
objectPos=c]{figure}{\includegraphics[width=353pt,height=290pt]{image}}%
[Commercial crude oil inventories, SPX excess returns, S\&P GCSI excess return time series]{Commercial crude oil inventories calculated as the logarithm of the current value divided by the mean of same weekly values over the past 5 years, Log excess returns on the S\&P Goldman Sachs Commodity Index,  Log excess returns on the S\&P 500 index.}{fig:testB}
\end{document}

-
@Herbert: When I try to add more firgure, i get: Appendix A. ! Missing number, treated as zero. <to be read again> \protect l.19 ...graphics[width=300pt,height=290pt]{image}} % ? Any idea why? –  latexmp Jun 7 '11 at 7:51
@latexmp: I modified the example to allow RotAngle= with an empty argument. In this case rotAngle=90 is assumed. However, you need for every image a label, otherwise \pageref won't work. We need this, because \ifodd\thepage didn't work in all cases. –  Herbert Jun 7 '11 at 8:16
@Herbert: thnks! Just one more question... Is it hard to make the horizontalplacement (objectPos) to left (l) on even pages and right (r) on odd pages? –  latexmp Jun 7 '11 at 8:47
@latexmp: no, you can do it in the same way as for RotAngle. Define a new key ObjectPos which uses the same \pageref{#1} for setting objectPos. It is also possible to set this inside the RotAngle key itself. –  Herbert Jun 7 '11 at 9:11
@Herbert: ok. If i try to make the image wider and higher, it sometimes jump to a new page, but do not rotate the right way. Also i struggle to get a figure at the same page as the heading if i try to make it wider. What i like is to use the full height of the page (width of figure) and adjust the width (height of the figure) so it fit the page, including the caption... –  latexmp Jun 7 '11 at 9:34

I would suggest you to create a command with the \ifthenelse setting the whole \hvFloat stuff, insted of just an argument for one of its options. Something like:

 \hvFloat[floatPos=htb,capVPos=c,rotAngle=90,objectPos=c]% options
{figure}%     float type
{\includegraphics[width=353pt,height=290pt]{#1}}%     object: Argument #1 Stands for the image location
[#2]%     Arg #2 = short caption
{#3}%     Arg #3 = long caption
{#4}%     Arg #4 = label
}{
\hvFloat[floatPos=htb,capVPos=c,rotAngle=270,objectPos=c]%     options
{figure}%     float type
{\includegraphics[width=353pt,height=290pt]{#1}}%     object: Argument #1 Stands for the image location
[#2]%     Arg #2 = short caption
{#3}%     Arg #3 = long caption
{#4}%     Arg #4 = label
}
}


(But that didn't work here...)

I managed to do something like without the hvfloat package, but I don't know if it suits your needs:

\newcommand{\currentside}[2]{\ifthenelse{\isodd{\thepage}}{%
\begin{figure}[htb]%
\includegraphics[height=\textwidth,angle=270]{#1}%
\caption{#2}%
\end{figure}%
}{%
\begin{figure}[htb]%
\includegraphics[height=\textwidth,angle=90]{#1}%
\caption{#2}%
\end{figure}%
}%
}

-