%% 
%% This is file `sectionbox.sty' v 1.01
%%
%% Author Michael H.F. Wilkinson 
%%   October 13, 2005
%% 
%% version 1.01, 2005/10/13:
%%               - widths of section boxes reduced by 2\colboxsep+3\fboxrule
%%                 which makes them properly flush with the current column 
%%                 width
%% version 1.00, 2005/08/24:
%%               - first release
%% 
%% 
\ProvidesPackage{sectionbox}[2005/10/13, v1.01 section boxes for posters (MHFW)]
\NeedsTeXFormat{LaTeX2e}[1995/06/01]

\RequirePackage{ifthen}
\RequirePackage{calc}
\RequirePackage{fancybox}
\RequirePackage{color}

\definecolor{sectboxrulecol}{rgb}{0,0,0}
\definecolor{sectboxfillcol}{rgb}{0.9,0.9,0.9}
\definecolor{sectboxtextcol}{rgb}{0,0,0}

\definecolor{subsectboxrulecol}{rgb}{0,0,0}
\definecolor{subsectboxfillcol}{rgb}{0.9,0.9,0.9}
\definecolor{subsectboxtextcol}{rgb}{0,0,0}

\definecolor{subsubsectboxrulecol}{rgb}{0,0,0}
\definecolor{subsubsectboxfillcol}{rgb}{0.9,0.9,0.9}
\definecolor{subsubsectboxtextcol}{rgb}{0,0,0}

\newlength{\sectboxskip}                          % skip below sectionbox
\setlength{\sectboxskip}{0.5ex plus0.1ex minus 0.5ex}
\newlength{\subsectboxskip}                       % skip below subsectionbox
\setlength{\subsectboxskip}{0.25ex plus0.1ex minus 0.25ex}
\newlength{\subsubsectboxskip}                    % skip below subsubsectionbox
\setlength{\subsubsectboxskip}{0.25ex plus0.1ex minus 0.25ex}
\newlength{\subsectmargin}                   %
\setlength{\subsectmargin}{0pt} 
\newlength{\subsubsectmargin}                   %
\setlength{\subsubsectmargin}{0pt} 

\newcommand{\makesectionbox}[1]{\fbox{#1}}         % default single frame box
\newcommand{\makesubsectionbox}[1]{\fbox{#1}}      % default single frame box
\newcommand{\makesubsubsectionbox}[1]{\fbox{#1}}   % default single frame box

\newcommand{\framesectionbox}{                     % set section boxes to single frame boxes
  \renewcommand{\makesectionbox}[1]{\fbox{##1}}
  \setlength{\sectboxskip}{0.5ex plus0.1ex minus 0.5ex}       
                                                   % set back to default
}

\newcommand{\framesubsectionbox}{                  % set section boxes to single frame boxes
  \renewcommand{\makesubsectionbox}[1]{\fbox{##1}}
  \setlength{\subsectboxskip}{0.25ex plus0.1ex minus 0.25ex0.5}    
                                                   % set back to default
  \setlength{\subsectmargin}{0pt} 
}

\newcommand{\framesubsubsectionbox}{               % set section boxes to single frame boxes
  \renewcommand{\makesubsubsectionbox}[1]{\fbox{##1}}
  \setlength{\subsubsectboxskip}{0.25ex plus0.1ex minus 0.25ex} 
                                                   % set back to default
  \setlength{\subsubsectmargin}{0pt} 
}

\newcommand{\doublesectionbox}{                    % set section boxes to double boxes
  \renewcommand{\makesectionbox}[1]{\doublebox{##1}}
  \setlength{\sectboxskip}{0.5ex plus0.1ex minus 0.5ex}       % set back to default
}

\newcommand{\doublesubsectionbox}{                 % set section boxes to double boxes
  \renewcommand{\makesubsectionbox}[1]{\doublebox{##1}}
  \setlength{\subsectboxskip}{0.25ex plus0.1ex minus 0.25ex}       
                                                   % set back to default
  \setlength{\subsectmargin}{0pt} 
}

\newcommand{\doublesubsubsectionbox}{              % set section boxes to double boxes
  \renewcommand{\makesubsubsectionbox}[1]{\doublebox{##1}}
  \setlength{\subsubsectboxskip}{0.25ex plus0.1ex minus 0.25ex}       % set back to default
  \setlength{\subsubsectmargin}{0pt} 
}

\newcommand{\shadowsectionbox}{                    % set section boxes to shadow boxes
  \renewcommand{\makesectionbox}[1]{\shadowbox{##1}}
  \setlength{\sectboxskip}{-2ex plus0.1ex minus 0.5ex}      % counteract effects of shadowbox
}

\newcommand{\shadowsubsectionbox}{          % set section boxes to shadow boxes
  \renewcommand{\makesubsectionbox}[1]{\shadowbox{##1}}
  \setlength{\subsectboxskip}{-2.25ex plus0.1ex minus 0.25ex}      
                                            % counteract effects of shadowbox
  \setlength{\subsectmargin}{\shadowsize} 
}

\newcommand{\shadowsubsubsectionbox}{                    % set section boxes to shadow boxes
  \renewcommand{\makesubsubsectionbox}[1]{\shadowbox{##1}}
  \setlength{\subsubsectboxskip}{-2.25ex plus0.1ex minus 0.25ex}  
                                             % counteract effects of shadowbox
  \setlength{\subsubsectmargin}{\shadowsize} 
}


\newsavebox{\sectsavebox}                          % saves contents of section box
\newsavebox{\subsectsavebox}                       % saves contents of subsection box
\newsavebox{\subsubsectsavebox}                    % saves contents of subsubsection box

\ifthenelse{\lengthtest{\paperwidth <\paperheight}}{% compute \fboxrule etc. 
  \setlength{\fboxrule}{0.0014\paperwidth}          % portrait mode
  \setlength{\shadowsize}{0.0042\paperwidth}
}{%
  \setlength{\fboxrule}{0.0014\paperheight}         % landscape mode
  \setlength{\shadowsize}{0.0042\paperheight}
}
\newlength{\colboxsep}                       % store value for \fcolsep for use in 
\setlength{\colboxsep}{2\fboxrule}            % the \colorbox 

\newenvironment{sectionbox}[2][\columnwidth]{% default width of minipage is \columnwidth
\setlength{\fboxsep}{0.5\fboxrule}% ensures colorbox is filled up to  
%                                   boundary of sectionbox 
\begin{lrbox}{\sectsavebox}                  % open lrbox and save in \sectsavebox
\begin{minipage}{#1-2\colboxsep-3\fboxrule}
\color{sectboxtextcol}%
\ifthenelse{\equal{#2}{}}{}{\section{#2}}%  only produce section if
%                                            mandatory parameter not empty
}{%
\end{minipage}                               
\end{lrbox}                                  % close lrbox
  \color{sectboxrulecol}                     % sets color of boundary
  \noindent
  \makesectionbox{\setlength{\fboxsep}{\colboxsep}\colorbox{sectboxfillcol}{\usebox{\sectsavebox}}}               
  \\[\sectboxskip]
}

\newenvironment{subsectionbox}[2][\columnwidth]{% default width of minipage is \columnwidth
\setlength{\fboxsep}{0.5\fboxrule}% ensures colorbox is filled up to  
%                                   boundary of sectionbox 
\begin{lrbox}{\subsectsavebox}                  % open lrbox and save in \subsectsavebox
\begin{minipage}{#1 -\subsectmargin - 2\colboxsep - 3\fboxrule}
\color{subsectboxtextcol}%
\ifthenelse{\equal{#2}{}}{}{\subsection{#2}}    % only produce subsection if
%                                                 mandatory parameter not empty
}{%
\end{minipage}                               
\end{lrbox}                                  % close lrbox
  \color{subsectboxrulecol}                     % sets color of boundary
  \noindent
  \makesubsectionbox{\setlength{\fboxsep}{\colboxsep}\colorbox{subsectboxfillcol}{\usebox{\subsectsavebox}}}               
  \\[\subsectboxskip]
}

\newenvironment{subsubsectionbox}[2][\columnwidth]{% default width of minipage is \columnwidth
\setlength{\fboxsep}{0.5\fboxrule}% ensures colorbox is filled up to  
%                                   boundary of sectionbox 
\begin{lrbox}{\subsubsectsavebox}                  % open lrbox and save in \subsectsavebox
\begin{minipage}{#1 -\subsubsectmargin - 2\colboxsep - 3\fboxrule}
\color{subsubsectboxtextcol}%
\ifthenelse{\equal{#2}{}}{}{\subsubsection{#2}}    % only produce subsection if
%                                                 mandatory parameter not empty
}{%
\end{minipage}                               
\end{lrbox}                                  % close lrbox
  \color{subsubsectboxrulecol}                     % sets color of boundary
  \noindent
  \makesubsubsectionbox{\setlength{\fboxsep}{\colboxsep}\colorbox{subsubsectboxfillcol}{\usebox{\subsubsectsavebox}}}               
  \\[\subsubsectboxskip]
}
