%frsample05 - sample
%sample with layout with usage of beside captions
\input pictures
\documentclass{book}

\usepackage{calc}
\usepackage{tabularx,array}
\usepackage{graphicx}

\IfFileExists{pstricks.sty}{\usepackage{pstricks}\psset{unit=1pt}}{}

\IfFileExists{fancyhdr.sty}{\RequirePackage{fancyhdr}\pagestyle{fancy}\fancyfoot{}
\fancyhead[LE]{\leavevmode\hspace*{-7cc}\def\arraystretch{1,2}\begin{tabular}{@{}l@{}}
  \rlap{\thepage}\hskip7cc\hbox to\textwidth{\slshape\leftmark\hfill}\strut\\\hline\end{tabular}}
\fancyhead[LO]{\leavevmode\hspace*{-7cc}\def\arraystretch{1.2}\begin{tabular}{@{}l@{}}
  \hskip7cc\hbox to\textwidth{\slshape\rightmark\quad\hfill\thepage}\strut\\\hline\end{tabular}}
\fancyhead[RE]{}\fancyhead[CE]{}
\fancyhead[RO]{}\fancyhead[CO]{}
\def\headrulewidth{0pt}}
{\pagestyle{plain}}

%load floatrow
\usepackage[font=small,captionskip=5pt,
   capbesideframe=yes]{floatrow}

%load caption
\usepackage[font=small,labelfont=bf,labelsep=period,
   justification=raggedright,singlelinecheck=no]{caption}[2004/11/28]

\DeclareMarginSet{hangleft}%
  {\setfloatmargins{\hskip-7cc}{\hfill}}

\DeclareFloatSeparators{cicero}{\hskip1cc}

\DeclareCaptionFormat{Hang}{\leftskip7cc\parindent0pt
  \noindent\llap{\hbox to\leftskip{#1#2\hfil}}#3\par}
\DeclareCaptionFormat{break}{#1#2\break#3}

\floatsetup[figure]{style=Boxed,
  capposition=beside,capbesidewidth=6cc,objectset=centering,
  capbesideposition=left,capbesidesep=cicero,
  floatwidth=\columnwidth,
  margins=hangleft}

\floatsetup[widefigure]{capposition=bottom}

\captionsetup[figure]{format=Hang,labelsep=none,justification=raggedright}
\captionsetup[capbesidefigure]%
   {format=default,labelsep=newline}

\DeclareNewFloatType{textbox}{fileext=lor,name=Text,placement=tp,within=chapter}

\DeclareMarginSet{capleft}%
  {\setfloatmargins{\hfill}{\hfill\hskip\FCwidth}}

\DeclareObjectSet{indent}{\raggedright\parindent15pt\parskip2pt}

\floatsetup[textbox]{style=Boxed,
  frameset={\fboxrule=1pt\fboxsep=12pt},
  capposition=beside,capbesideposition=left,
  floatwidth=6cm,capbesidewidth=4.5cc,
  capbesidesep=cicero,margins=capleft,
  objectset=indent}

\floatsetup[widetextbox]{capposition=bottom,
  floatwidth=\columnwidth,margins=raggedright}

\captionsetup[textbox]{justification=raggedright}
\captionsetup[capbesidetextbox]%
  {format=break,labelsep=none,justification=raggedleft}

\providecommand*{\pkg}[1]{\texttt{#1}}
\newfloatcommand{ttextbox}{textbox}
\providecommand*{\pkg}[1]{\texttt{#1}}
\providecommand*{\env}[1]{\texttt{#1}}
\providecommand*{\com}[1]{\texttt{\char`\\#1}}
\providecommand*{\meta}[1]{$\langle$\textit{#1}$\rangle$}
\setcounter{topnumber}{1}

\def\TEXTBOX{Here goes first line of text \text

There goes second line of text

Thence goes third line of text \text

Hence goes fourth line of text}

\parskip0pt
\begin{document}

\chapter{Beside and Other Captions (Beta-Version Example)}

\begin{sl}
This example shows floats in one-column document in facing layouts.

\emph{Common float settings}\\
Font for float contents \verb|\small|;
\com{captionskip} is defined as 5pt;
separation between beside float boxes equals to 2\,em;
flag for captions beside framed object is true (frames will be defined later).
\begin{verbatim}
\usepackage[font=small,captionskip=5pt,
   capbesideframe=yes]{floatrow}
\end{verbatim}

\emph{Common caption settings.}\\
For caption text used \verb|\small| font;
caption label font bold;
label separated by period sign;
justification left;
one-line captions have the same alignment as multiline ones.
\begin{verbatim}
\usepackage[font=small,labelfont=bf,labelsep=period,
   justification=raggedright,singlelinecheck=no]{caption}
\end{verbatim}

\emph{Special caption settings for current float types.}

\emph{Figure.}\\
Label hangs on the left margin without label separator; justification left.
In beside captions label is placed above caption text.
\begin{verbatim}
\DeclareCaptionFormat{Hang}{\leftskip7cc\parindent0pt
  \noindent\llap{\hbox to\leftskip{#1#2\hfil}}#3\par}
\captionsetup[figure]%
   {format=Hang,labelsep=none,justification=raggedright}
\captionsetup[capbesidefigure]%
   {format=default,labelsep=newline}
\end{verbatim}

\emph{Textbox.}\\
Justification left.
For beside captions used \texttt{break} style (the \texttt{labelsep=none} won't help here, because of
\verb|\newline| command adds a glue at the end of line); justification right.
\begin{verbatim}
\captionsetup[textbox]{justification=raggedright}
\DeclareCaptionFormat{break}{#1#2\break#3}
\captionsetup[capbesidetextbox]%
  {format=break,labelsep=none,justification=raggedleft}
\end{verbatim}

\emph{Special settings for float types.}

\emph{Figure.}\\
For figures is used \texttt{Boxed} style;
captions always beside object and have width of margin (with separation);
they always placed on the left margin and separated by 1~cicero space;
object contents centered;
the default width of float object equals to text width;
float margins hang to the left by 7~cicero.

The wide figures (starred environment) put captions below object
\begin{verbatim}
\DeclareMarginSet{hangleft}%
  {\setfloatmargins{\hskip-7cc}{\hfill}}
\floatsetup[figure]{style=Boxed,
  capposition=beside,capbesidewidth=6cc,objectset=centering,
  capbesideposition=left,capbesidesep=cicero,
  floatwidth=\columnwidth,
  margins=hangleft}

\floatsetup[widefigure]{capposition=bottom}
\end{verbatim}

\emph{Textbox.}\\
The new float \env{textbox} uses corrected \texttt{Boxed} style;
caption always stays beside float object---on the left side;
the default width of float object 6 centimeters;
the default width of caption 4.5~cicero;
caption separated from objects by 1~cicero;
margins use settings which center float object;
object contents flushed to left margins;
\verb|\parindent|${{}=15}$\,pt, \verb|\parskip|${{}=2}$\,pt.

For wide text boxes caption placed below float object;
the default object width equals to text width;
float box alignment left.
\begin{verbatim}
\DeclareMarginSet{capleft}%
  {\setfloatmargins{\hfill}{\hfill\hskip\FCwidth}}

\DeclareObjectSet{indent}{\raggedright\parindent15pt\parskip2pt}

\floatsetup[textbox]{style=Boxed,
  frameset={\fboxrule=1pt\fboxsep=12pt},
  capposition=beside,capbesideposition=left,
  floatwidth=6cm,capbesidewidth=4.5cc,
  capbesidesep=cicero,margins=capleft,
  objectset=indent}

\floatsetup[widetextbox]{capposition=bottom,
  floatwidth=\columnwidth,margins=raggedright}
\end{verbatim}

\end{sl}

\widowpenalty10000

\def\text{{\mdseries
And more text and some more text and a bit more text and
a little more text and a little peace of text to fill space}}

\def\Text{{\mdseries
\text. \text. \text.  \text. \par \text. \text. \text.}}

\unitlength1.44pt
\ifx\pspicture\undefined\else\psset{unit=\unitlength}\fi
\bfseries
\clearpage

Example of plain \env{figure} environment (figure~\ref{float:plain:fig}).
\begin{figure}
  {\unitlength.85\unitlength\ifx\pspicture\undefined\else\psset{unit=\unitlength}\fi
  \input{BlackCat.picture}}%
  \caption{Plain figure}%
\label{float:plain:fig}%
\end{figure}%
\Text

\Text

Example of plain \env{textbox} environment (text~\ref{float:plain:text1}).
The width of object equals to 6\,cm.
\begin{textbox}
\TEXTBOX
\caption{Plain textbox without any settings}%
\label{float:plain:text1}%
\end{textbox}%
\Text

\Text

Example of plain \env{textbox} environment (text~\ref{float:plain:text2}) with defined width
\begin{verbatim}
\thisfloatsetup{floatwidth=8cm}
\end{verbatim}
This width is a bit more than \verb|\textwidth-2\captionwidth| value.

\thisfloatsetup{floatwidth=8cm}
\begin{textbox}
\TEXTBOX
\caption{Plain textbox. Width settings}%
\label{float:plain:text2}%
\end{textbox}%
\Text

\Text

Example of plain \env{textbox} environment (text~\ref{float:plain:text3}) with defined width
\begin{verbatim}
\thisfloatsetup{floatwidth=5cm}
\end{verbatim}
This width less than \verb|\textwidth-2\captionwidth| value.

\thisfloatsetup{floatwidth=5cm}
\begin{textbox}[!tb]
\TEXTBOX
\caption{Plain textbox. Width settings}%
\label{float:plain:text3}%
\end{textbox}%
\Text

Example of plain \env{figure} environment (figure~\ref{float:W:plain:fig2})
with predefined width${{}=5}$\,cm.
\begin{verbatim}
\thisfloatsetup{floatwidth=5cm}
\end{verbatim}
\thisfloatsetup{floatwidth=5cm}%floatrow
\begin{figure}
  {\unitlength.85\unitlength\ifx\pspicture\undefined\else\psset{unit=\unitlength}\fi
  \input{BlackCat.picture}}%
  \caption{Plain figure with changed width}%
  \label{float:W:plain:fig2}%
\end{figure}%
\Text

\Text


Example of two-column or wide plain figure (see figure~\ref{float:wide:fig3}).
\begin{figure*}
  {\unitlength.85\unitlength\ifx\pspicture\undefined\else\psset{unit=\unitlength}\fi
  \input{BlackCat.picture}}%
  \caption{%
Plain wide figure. \text}%
\label{float:wide:fig3}%
\end{figure*}%
\Text

\Text

\Text


Example of plain \env{figure} environment (figure~\ref{wfloat:W:plain:fig4})
with predefined width${{}=9}$\,cm.
\begin{verbatim}
\thisfloatsetup{floatwidth=9cm}
\end{verbatim}
The real width equals to 9\,cm${}+{}$margin width

\thisfloatsetup{floatwidth=9cm}
\begin{figure*}
  {\unitlength.85\unitlength\ifx\pspicture\undefined\else\psset{unit=\unitlength}\fi
  \input{BlackCat.picture}}%
  \caption{Plain figure with changed width}%
\label{wfloat:W:plain:fig4}%
\end{figure*}%

\Text

Example of plain ``wide'' \env{textbox} environment with predefined width
(see text~\ref{float:prewide:text5}).
\begin{verbatim}
\thisfloatsetup{floatwidth=.7\textwidth}
\end{verbatim}

\thisfloatsetup{floatwidth=.7\textwidth}
\begin{textbox*}
  \TEXTBOX
  \caption{Plain wide textbox. Changed width}%
  \label{float:prewide:text5}%
\end{textbox*}%

\Text

Example of plain ``wide'' \env{textbox} environment
(see text~\ref{float:wide:text6}).
\begin{textbox*}[!tbp]
\TEXTBOX
  \caption{Plain wide textbox}%
\label{float:wide:text6}%
\end{textbox*}%

\Text

\Text

Example of figure placed in \verb|\fcapside| (\verb|\floatbox| stuff for usage of beside captions);
the width of float box equals  to the width of graphics
(see figure~\ref{floatbox:FB:fig7}).
\begin{figure}
\fcapside[\FBwidth]
  {\unitlength2.8\unitlength\ifx\pspicture\undefined\else\psset{unit=\unitlength}\fi
  \input{TheCat.picture}}
  {\caption{%
Figure (\protect\com{ffigbox})
width of graphics}\label{floatbox:FB:fig7}}
\end{figure}%
\Text

\Text

Example of wide figure placed in \verb|\ffigbox| (\verb|\floatbox| stuff);
the width of float box equals  to the width of grahics
(see figure~\ref{floatbox:FB:fig8}).
\begin{figure*}
\ffigbox[\FBwidth]
  {\unitlength2.8\unitlength\ifx\pspicture\undefined\else\psset{unit=\unitlength}\fi
  \input{TheCat.picture}}
  {\caption{%
Wide figure (\protect\com{ffigbox})
width of graphics}\label{floatbox:FB:fig8}}
\end{figure*}%
\Text



\end{document}
