%frsample06 - sample
%one-column facing layout with miscellaneous caption settings
\input pictures
\documentclass{book}

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

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

%load floatrow
\usepackage{floatrow}

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

%load subfig
\newif\ifLoadSubfig
\IfFileExists{subfig.sty}{\usepackage[justification=raggedright,
   singlelinecheck=no,captionskip=7pt]{subfig}
\LoadSubfigtrue}{\LoadSubfigfalse}

\LoadSubfigfalse

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

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

\floatsetup[textbox]{style=Boxed,heightadjust=all,
  frameset={\fboxrule=1pt\fboxsep=12pt},
  margins=raggedright,captionskip=7pt,
  capposition=bottom,objectset=indent,
  capbesideframe=yes,capbesideposition=outside,
  capbesidewidth=\marginparwidth,valign=t}

%\DeclareMarginSet{hangoutside}%
%  {\setfloatmargins*
%    {\hfil}{\hskip-\marginparwidth\hskip-\marginparsep}}

\floatsetup[widetextbox]{margins=hangoutside,facing=yes,
  floatwidth=\textwidth}
\floatsetup[textboxrow]{floatwidth=sidefil}
%\makeatletter
%\DeclareCaptionFormat{hangorbreak}{\FBiffloatrow{#1#2#3\par
%  }{\@hangfrom{#1#2}%
%    \advance\caption@parindent\hangindent
%    \advance\caption@hangindent\hangindent
%    #3\par
%  }}
%\makeatother

\DeclareCaptionFormat{marginpars}{\vbox to0pt{\RaggedRight\FBifcaptop\vss\relax
      \floatfacing
        {\addtolength\leftskip{\textwidth+1em}}%
        {\addtolength\rightskip{\textwidth+1em}}%
      #1\par#3%
      \FBifcaptop\relax\vss}}

\captionsetup[textbox]{justification=justified,format=hang}
\captionsetup[textboxrow]{justification=justified,format=default,labelsep=newline}

\captionsetup[capbesidetextbox]{justification=raggedright,
  format=default,labelsep=newline}

\captionsetup[widetextbox]{format=marginpars}

\newif\ifLoadRotating
\IfFileExists{rotating.sty}
{\usepackage[figuresright]{rotating}
\DeclareMarginSet{expand}%
  {\setfloatmargins
    {\hfil}{\hskip-\headsep\hskip-.7\headheight plus1fil}}

\floatsetup[rotfloat]{capbesideposition=right,margins=expand,
  facing=no,capbesidewidth=none}
\LoadRotatingtrue}{\LoadRotatingfalse}

\let\wideemptyfloatpage\emptyfloatpage

\providecommand*{\pkg}[1]{\texttt{#1}}
\providecommand*{\com}[1]{\texttt{\char`\\#1}}
\providecommand*{\Lopt}[1]{\textsf{#1}}
\providecommand*{\file}[1]{\texttt{#1}}
\providecommand*{\env}[1]{\texttt{#1}}
\providecommand*{\meta}[1]{$\langle$\textit{#1}$\rangle$}

\newfloatcommand{ttextbox}{textbox}

\makeatletter
\newcommand\ifTwocolumn{\if@twocolumn}
\newcommand\Resizebox[5]{\setbox0\hbox{\setlength\unitlength{#1/#3}{#5}}%
 \@tempdima\ht0\advance\@tempdima\dp0%
 \ifdim\@tempdima>#2\setlength\unitlength{#2/#4}{#5}\else\box0\fi}
\makeatother

\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.} }

\unitlength1.44pt

\newcommand\TEXTBOX[1][]{%
Here goes first line of text \text\par
There goes second line of text#1\par
Thence goes third line of text \text\par
Hence goes fourth line of text}

\begin{document}
\providecommand\RaggedRight{\raggedright}

\chapter{One Column Facing~Document
(Beta-Version~Example)}
\markboth{One Column Facing Document}{One Column Facing Document}
\begin{sl}
This example shows floats in one-column document in facing layouts.

\emph{Common caption settings.}\\
For caption text used \verb|\small| font;
caption label font bold, separated
by period sign.
\begin{verbatim}
\usepackage[font=small,labelfont=bf,labelsep=period,
   singlelinecheck=no]{caption}
\end{verbatim}

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

\emph{Textbox.}\\
Justified alignment.
If float stays alone caption label hangs to the left;
if float stays in \env{floatrow} environment---there is used normal float style (with in-line caption label).

In beside captions caption label stays separately on line. Justification left.

For captions in wide floats (which climb out to the left margin) used miscellaneous format,
which in \env{floatrow} environment restored to normal.
\begin{verbatim}
\makeatletter
\DeclareCaptionFormat{hangorbreak}{\FBiffloatrow#1#2#3\par
  \else\@hangfrom{#1#2}%
    \advance\captionparindent\hangindent
    \advance\captionhangindent\hangindent
    #3\par\fi}
\makeatother

\DeclareCaptionFormat{marginpars}{\FBiffloatrow#1#2#3\par
  \else
    \vbox to0pt{\RaggedRight\FBifcaptop\vss\fi
      \floatfacing
        {\addtolength\leftskip{\textwidth+1em}}%
        {\addtolength\rightskip{\textwidth+1em}}%
      #1\par#3%
      \FBifcaptop\else\vss\fi}\fi}

\captionsetup[textbox]{justification=justified,
  format=hangorbreak}

\captionsetup[capbesidetextbox]{justification=raggedright,
  format=default,labelsep=newline}

\captionsetup[widetextbox]{format=marginpars}
\end{verbatim}

\emph{Common subcaption settings.}\\
Justification left. One line subcaptions have the same alignment.
\begin{verbatim}
\usepackage[justification=raggedright,
   singlelinecheck=no]{subfig}
\end{verbatim}

\emph{Special settings for float types.}

\emph{Textbox.}\\
The new float textbox uses
corrected \texttt{Boxed} style; object contents flushed to left margins;
\verb|\captionskip| defined as 7~pt;
captions below objects;
object contents; alignment: \verb|\parindent|${{}=15}$\,pt, \verb|\parskip|${{}=2}$\,pt;
beside captions aligned to frames;
width of beside captions equals to margin width;
objects aligned by top line.
\begin{verbatim}
\DeclareObjectSet{indent}{\raggedright\parindent15pt\parskip2pt}

\floatsetup[textbox]{style=Boxed,heightadjust=all,
  frameset={\fboxrule=1pt\fboxsep=12pt},
  margins=raggedright,captionskip=7pt,
  capposition=bottom,objectset=indent,
  capbesideframe=yes,capbesideposition=outside,
  capbesidewidth=\marginparwidth,valign=t}
\end{verbatim}

\emph{Special settings for special float layout.}

\emph{Wide float.}\\
For wide float set hanged indentation to binder margin;
the default width of object equals ti text width;
The facing control switched on.
\begin{verbatim}
\DeclareMarginSet{hangoutside}%
  {\setfloatmargins*
    {\hfil}{\hskip-\marginparwidth\hskip-\marginparsep}}

\floatsetup[widetextbox]{margins=hangoutside,facing=yes,
  floatwidth=\textwidth}
\end{verbatim}

\emph{Rotated float.}\\
For rotated floats beside caption placed to right side of object;
right side expanded to the top of running head. To delete running head from pages
with rotated float was used \verb|\emptyfloatpage| macro\footnote{In current example the
\protect\com{wideemptyfloatpage} command is the synonym.} and
loaded \pkg{floatpagestyle} package.
\begin{verbatim}
\DeclareMarginSet{expand}%
  {\setfloatmargins
    {\hfil}{\hskip-\headsep\hskip-.7\headheight plus1fil}}

\floatsetup[rotfloat]{capbesideposition=right,margins=expand,
  facing=no,capbesidewidth=none}
\end{verbatim}

For this document there was also used special page style for running heads
using \pkg{fancyhdr}. If this style exists on your system the special page
style will be loaded otherwise the \texttt{plain} page style used.
\end{sl}

\clearpage
\bfseries

Example of plain \env{textbox} environment (text~\ref{float:plain:text}).

\tracingmacros=1
\begin{textbox}
\TEXTBOX
\caption{Plain \env{textbox} environment. \text }%
\label{float:plain:text}%
\end{textbox}

\Text

\clearpage

Example of plain \env{textbox} environment (box~\ref{float:w:plain:Text})
with predefined width.
\begin{verbatim}
\thisfloatsetup{floatwidth=7cm}
\end{verbatim}

\thisfloatsetup{floatwidth=7cm}
\begin{textbox}
\caption{Plain  \env{textbox} environment with predefined width. \text}\label{float:w:plain:Text}
\TEXTBOX
\end{textbox}

\Text

\clearpage

Example of textbox placed in \verb|\ttextbox| (\verb|\floatbox| stuff);
the width of float box equals to defined width
(see text box~\ref{floatbox:FB:text}).
\begin{verbatim}
\ttextbox[.85\hsize]
   ...
\end{verbatim}

\begin{textbox}
\ttextbox[.85\hsize]
  {\TEXTBOX}
  {\caption{%
The \env{textbox} environment including \protect\com{ttextbox}
with defined width. \text}\label{floatbox:FB:text}}
\end{textbox}

\Text

\ifLoadSubfig

\clearpage
Example of float with beside caption (see text box~\ref{floatbox:beside:text})
with two subboxes~\subref{subtext:A} and \subref{subtext:B}.
These subfloats are placed inside \env{subfloatrow} environment, left subfloat has width 6\,cm,
second---occupies the rest width of row.
\begin{verbatim}
\begin{textbox}
\ttextbox
{\vspace{-\topskip}\begin{subfloatrow}
\subfloat[First ...\label{...}]{\vbox{\hsize6cm...}}

\subfloat[Second ...\label{...}]{\vbox{\hsize\Xhsize...}}
\end{subfloatrow}}
{\caption{...}\label{...}}
\end{textbox}
\end{verbatim}

Since the \verb|\subfloat| macro uses \verb|\vtop| during subfloat building, before \env{subfloatrow}
environment was placed compensated space
\begin{verbatim}
\vspace{-\topskip}
\end{verbatim}

\begin{textbox}
\ttextbox
{\vspace{-\topskip}\begin{subfloatrow}
\subfloat[First text box\label{subtext:A}]%
{\vbox{\hsize6cm\TEXTBOX}}

\subfloat[Second text box with long long subcaption\label{subtext:B}]%
{\vbox{\hsize\Xhsize\TEXTBOX}}
\end{subfloatrow}}
{\caption{The \env{textbox} environment with subfloats. \text}%
\label{floatbox:subfloat:text}}
\end{textbox}

%\Text

\fi

\ifTwocolumn\else

\clearpage

Example of text box with beside caption (see box~\ref{floatbox:subfloat:text}).
\begin{verbatim}
\thisfloatsetup{capposition=beside,capbesidewidth=none}
\end{verbatim}
Since the \env{textbox} setup defines width for beside caption, there
was redefined key \texttt{capbesidewidth=none}.
Both caption and float object occupy 1``column'' width.

\thisfloatsetup{capposition=beside,capbesidewidth=none}
\begin{textbox}
{\TEXTBOX}
{\caption{Beside caption. The width of object equals
to 1``column'' width. \text}%
\label{floatbox:beside:text}}
\end{textbox}

\Text

\fi

\clearpage

Examples of plain wide \env{textbox} environments
(see text boxes~\ref{float:wide:text}--\ref{floatbox:wideii:text}).

For text box \ref{floatbox:wideii:text}  (at the bottom of page~\pageref{floatbox:wideii:text})
was redefined position of caption
\begin{verbatim}
\floatsetup[textbox]{capposition=top}
\end{verbatim}
inside group.

\begin{textbox*}
\TEXTBOX
  \caption{Plain wide textbox. \text }%
\label{float:wide:text}%
\end{textbox*}

\Text

\Text

\Text

\Text

\Text
\text.

\Text

\begin{textbox*}[h]
{\TEXTBOX}
{\caption{Plain wide textbox with \texttt{[h]} placement option. \text}%
\label{floatbox:widei:text}}
\end{textbox*}


\Text
\text.

\begingroup
\floatsetup[textbox]{capposition=top}
\begin{textbox*}[b]
{\TEXTBOX}
{\caption{Plain wide textbox with \texttt{[b]} placement option. \text}%
\label{floatbox:wideii:text}}
\end{textbox*}
\endgroup

\text.
\text.


\clearpage

Example of text box with beside caption (see text box~\ref{floatbox:wbeside:text}).
The default settings of caption and text box width put text box' contents at the space of main
text and caption at the space of marginal paragraphs.

\thisfloatsetup{capposition=beside}
\begin{textbox*}
{\TEXTBOX}
{\caption{Wide beside caption with default settings. \text}%
\label{floatbox:wbeside:text}}
\end{textbox*}

\Text

\Text

\Text

\clearpage

Example of  row with two textboxes
(boxes~\ref{row:text:I}--\ref{row:text:II}).

\begin{textbox*}
\begin{floatrow}
\ttextbox
{\TEXTBOX\footnote{Text of footnote. \text}}
{\caption{Beside text~I in float row. \text}%
\label{row:text:I}}%

\floatbox{textbox}
{\TEXTBOX. \text.

\floatfoot{Text of float foot. \text}}%
{\caption{Beside text~II in float row}%
\label{row:text:II}}%
\end{floatrow}
\end{textbox*}

\Text

\ifLoadRotating
\newlength\rotatedheight\rotatedheight\textwidth

\clearpage

Example of plain rotated text box with beside caption
(see figure~\ref{rot:beside:text} on page~\pageref{rot:beside:text}).

\thisfloatsetup{capposition=beside}
\begin{sidewaystextbox}
\emptyfloatpage
{\TEXTBOX[ \text.]}
{\caption{Beside caption. \text. \text. \text}%
\label{rot:beside:text}}
\end{sidewaystextbox}

\Text

\Text

\clearpage

Example of rotated float row with text boxes
(see texts~\ref{row:textI:I}--\ref{row:textI:II} on page~\pageref{row:textI:II}).

\begin{sidewaystextbox}
\wideemptyfloatpage
\begin{floatrow}
\ttextbox
{\TEXTBOX\par\TEXTBOX\footnote
{Text of footnote. \text}}
{\caption{Beside text~I. \text}%
\label{row:textI:I}}%

\floatbox{textbox}
{\caption{Beside text~II}%
\label{row:textI:II}%
\floatfoot{Text of float foot. \text}%
}%
{\TEXTBOX[ \text.]}%
\end{floatrow}
\end{sidewaystextbox}

\Text \Text \Text

\Text \Text

\fi

\end{document}
