%%
%% This is file `diagbox.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% diagbox.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2011--2020 by Leo Liu <leoliu.pku@gmail.com>
%% --------------------------------------------------------------------------
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{diagbox}
    [2020/02/09 v2.3 Making table heads with diagonal lines]
\RequirePackage{keyval}
\RequirePackage{pict2e}
\RequirePackage{calc}
\RequirePackage{array}
\newbox\diagbox@boxa
\newbox\diagbox@boxb
\newbox\diagbox@boxm
\newdimen\diagbox@wd
\newdimen\diagbox@ht
\newdimen\diagbox@insepl
\newdimen\diagbox@insepr
\newdimen\diagbox@outsepl
\newdimen\diagbox@outsepr
\def\diagbox@clear{%
  \diagbox@wd=\z@
  \diagbox@ht=\z@
  \diagbox@insepl=\tabcolsep
  \diagbox@insepr=\tabcolsep
  \diagbox@outsepl=-\tabcolsep
  \diagbox@outsepr=-\tabcolsep
}
\define@key{diagbox}{width}{%
  \unless\ifdim\diagbox@wd=\z@
    \PackageWarning{diagbox}%
      {You should not set width/innerwidth option more than once.}%
  \fi
  \setlength{\diagbox@wd}{#1}}
\define@key{diagbox}{height}{%
  \let\diagbox@save@line\line
  \def\line{\normalbaselineskip}%
  \setlength{\diagbox@ht}{#1}%
  \let\line\diagbox@save@line}
\define@key{diagbox}{innerleftsep}{%
  \setlength{\diagbox@insepl}{#1}}
\define@key{diagbox}{innerrightsep}{%
  \setlength{\diagbox@insepr}{#1}}
\define@key{diagbox}{innerwidth}{%
  \unless\ifdim\diagbox@wd=\z@
    \PackageWarning{diagbox}%
      {You should not set width/innerwidth option more than once.}%
  \fi
  \setlength{\diagbox@wd}{#1+\diagbox@insepl+\diagbox@insepr}}
\define@key{diagbox}{outerleftsep}{%
  \setlength{\diagbox@outsepl}{#1}}
\define@key{diagbox}{outerrightsep}{%
  \setlength{\diagbox@outsepr}{#1}}
\define@key{diagbox}{leftsep}{%
  \setlength{\diagbox@insepl}{#1}%
  \setlength{\diagbox@outsepl}{(#1)*-1}}
\define@key{diagbox}{rightsep}{%
  \setlength{\diagbox@insepr}{#1}%
  \setlength{\diagbox@outsepr}{(#1)*-1}}
\define@key{diagbox}{trim}{%
  \@tfor\@reserveda:=#1\do{%
    \ifcsname diagbox@insep\@reserveda\endcsname
      \setlength{\csname diagbox@insep\@reserveda\endcsname}{\z@}%
      \setlength{\csname diagbox@outsep\@reserveda\endcsname}{\z@}%
    \else
      \PackageError{diagbox}{Unknown trim option `#1'.}{l, r, lr and rl are supported.}%
    \fi}}
\define@key{diagbox}{dir}{%
  \def\diagbox@dir{#1}%
  \unless\ifcsname diagbox@dir@#1\endcsname
    \PackageError{diagbox}{Unknown direction `#1'.}{NW, NE, SW, SE are supported.}%
    \def\diagbox@dia{NW}%
  \fi}
\let\diagbox@dir@SE\relax
\let\diagbox@dir@SW\relax
\let\diagbox@dir@NE\relax
\let\diagbox@dir@NW\relax
\define@key{diagbox}{linewidth}{%
  \setlength{\@tempskipa}{#1}%
  \linethickness{\@tempskipa}}
\define@key{diagbox}{linecolor}{%
  \def\diagbox@setlinecolor{\color{#1}}}
\let\diagbox@setlinecolor\empty
\define@key{diagbox}{font}{%
  \def\diagbox@font{#1}}
\let\diagbox@font\empty
\def\diagbox@pict{%
  \unitlength\p@
  \begin{picture}
    (\strip@pt\dimexpr\diagbox@wd+\diagbox@outsepl+\diagbox@outsepr\relax,\strip@pt\diagbox@ht)
    (\strip@pt\dimexpr-\diagbox@outsepl\relax,0)
      \@nameuse{diagbox@\diagbox@part @pict@\diagbox@dir}
  \end{picture}}
\def\diagbox@double@pict@SE{%
  \put(0,0) {\makebox(0,0)[bl]{\box\diagbox@boxa}}
  \put(\strip@pt\diagbox@wd,\strip@pt\diagbox@ht) {\makebox(0,0)[tr]{\box\diagbox@boxb}}
  \diagbox@setlinecolor
  \Line(0,\strip@pt\diagbox@ht)(\strip@pt\diagbox@wd,0)}
\let\diagbox@double@pict@NW\diagbox@double@pict@SE
\def\diagbox@double@pict@NE{%
  \put(0,\strip@pt\diagbox@ht) {\makebox(0,0)[tl]{\box\diagbox@boxa}}
  \put(\strip@pt\diagbox@wd,0) {\makebox(0,0)[br]{\box\diagbox@boxb}}
  \diagbox@setlinecolor
  \Line(0,0)(\strip@pt\diagbox@wd,\strip@pt\diagbox@ht)}
\let\diagbox@double@pict@SW\diagbox@double@pict@NE
\def\diagbox@double#1#2#3{%
  \begingroup
  \diagbox@clear
  \def\diagbox@part{double}%
  \setkeys{diagbox}{dir=NW,#1}%
  \setbox\diagbox@boxa=\hbox{%
    \begin{tabular}{@{\hspace{\diagbox@insepl}}>{\diagbox@font}l@{}}
      #2
    \end{tabular}}%
  \setbox\diagbox@boxb=\hbox{%
    \begin{tabular}{@{}>{\diagbox@font}r@{\hspace{\diagbox@insepr}}}
      #3
    \end{tabular}}%
  \ifdim\diagbox@wd=\z@
    \ifdim\wd\diagbox@boxa>\wd\diagbox@boxb
      \diagbox@wd=\dimexpr2\wd\diagbox@boxa+\diagbox@insepl+\diagbox@insepr\relax
    \else
      \diagbox@wd=\dimexpr2\wd\diagbox@boxb+\diagbox@insepl+\diagbox@insepr\relax
    \fi
  \fi
  \ifdim\diagbox@ht=\z@
    \diagbox@ht=\dimexpr\ht\diagbox@boxa+\dp\diagbox@boxa+\ht\diagbox@boxb+\dp\diagbox@boxb\relax
  \fi
  $\vcenter{\hbox{\diagbox@pict}}$%
  \endgroup}
\def\diagbox@triple@setbox@NW#1#2#3{%
  \setbox\diagbox@boxa=\hbox{%
    \begin{tabular}{@{\hspace{\diagbox@insepl}}>{\diagbox@font}l@{}}
      #1
    \end{tabular}}%
  \setbox\diagbox@boxm=\hbox{%
    \begin{tabular}{@{\hspace{\diagbox@insepl}}>{\diagbox@font}l@{}}
      #2
    \end{tabular}}%
  \setbox\diagbox@boxb=\hbox{%
    \begin{tabular}{@{}>{\diagbox@font}r@{\hspace{\diagbox@insepr}}}
      #3
    \end{tabular}}}
\let\diagbox@triple@setbox@SW\diagbox@triple@setbox@NW
\def\diagbox@triple@setbox@SE#1#2#3{%
\setbox\diagbox@boxa=\hbox{%
  \begin{tabular}{@{\hspace{\diagbox@insepl}}>{\diagbox@font}l@{}}
    #1
  \end{tabular}}%
\setbox\diagbox@boxm=\hbox{%
  \begin{tabular}{@{}>{\diagbox@font}r@{\hspace{\diagbox@insepr}}}
    #2
  \end{tabular}}%
\setbox\diagbox@boxb=\hbox{%
  \begin{tabular}{@{}>{\diagbox@font}r@{\hspace{\diagbox@insepr}}}
    #3
  \end{tabular}}}
\let\diagbox@triple@setbox@NE\diagbox@triple@setbox@SE
\def\diagbox@triple@pict@NW{%
  \put(0,0)   {\makebox(0,0)[bl]{\box\diagbox@boxa}}
  \put(0,\y)  {\makebox(0,0)[tl]{\box\diagbox@boxm}}
  \put(\x,\y) {\makebox(0,0)[tr]{\box\diagbox@boxb}}
  \diagbox@setlinecolor
  \Line(0,\yym)(\x,0)
  \Line(\xm,\y)(\x,0)}
\def\diagbox@triple@pict@NE{%
  \put(0,\y)  {\makebox(0,0)[tl]{\box\diagbox@boxa}}
  \put(\x,\y) {\makebox(0,0)[tr]{\box\diagbox@boxm}}
  \put(\x,0)  {\makebox(0,0)[br]{\box\diagbox@boxb}}
  \diagbox@setlinecolor
  \Line(0,0)(\xxm,\y)
  \Line(0,0)(\x,\yym)}
\def\diagbox@triple@pict@SW{%
  \put(0,\y) {\makebox(0,0)[tl]{\box\diagbox@boxa}}
  \put(0,0)  {\makebox(0,0)[bl]{\box\diagbox@boxm}}
  \put(\x,0) {\makebox(0,0)[br]{\box\diagbox@boxb}}
  \diagbox@setlinecolor
  \Line(0,\ym)(\x,\y)
  \Line(\xm,0)(\x,\y)}
\def\diagbox@triple@pict@SE{%
  \put(0,0)   {\makebox(0,0)[bl]{\box\diagbox@boxa}}
  \put(\x,0)  {\makebox(0,0)[br]{\box\diagbox@boxm}}
  \put(\x,\y) {\makebox(0,0)[tr]{\box\diagbox@boxb}}
  \diagbox@setlinecolor
  \Line(0,\y)(\xxm,0)
  \Line(0,\y)(\x,\ym)}
\def\diagbox@triple#1#2#3#4{%
  \begingroup
  \diagbox@clear
  \def\diagbox@part{triple}%
  \setkeys{diagbox}{dir=NW,#1}%
  \@nameuse{diagbox@triple@setbox@\diagbox@dir}{#2}{#3}{#4}%
  \diagbox@solve@equations
  $\vcenter{\hbox{\diagbox@pict}}$%
  \endgroup}
\newcommand\diagbox[3][]{%
  \@ifnextchar\bgroup
    {\diagbox@triple{#1}{#2}{#3}}{\diagbox@double{#1}{#2}{#3}}}
\expandafter\xdef\csname ver@slashbox.\@pkgextension\endcsname{9999/99/99}
\def\slashbox{%
  \def\diagbox@slashbox@options{dir=SW,}%
  \slashbox@}
\def\backslashbox{%
  \def\diagbox@slashbox@options{dir=NW,}%
  \slashbox@}
\newcommand\slashbox@[1][]{%
  \ifx\relax#1\relax\else
    \edef\diagbox@slashbox@options{%
      \unexpanded\expandafter{\diagbox@slashbox@options}%
      \unexpanded{width=#1,}}%
  \fi
  \slashbox@@}
\newcommand\slashbox@@[3][]{%
  \edef\diagbox@slashbox@options{%
    \unexpanded\expandafter{\diagbox@slashbox@options}%
    \unexpanded{trim=#1,}}%
  \expandafter\diagbox\expandafter[\diagbox@slashbox@options]{#2}{#3}}
\ifcsname\detokenize{fp_eval:n}\endcsname
\csname fi\endcsname
\ExplSyntaxOn
\cs_new_protected:Npn \__diagbox_solve_equations:
  {
    \fp_set:Nn \l__diagbox_xa_fp
      { \dim_to_fp:n { \wd \diagbox@boxa } }
    \fp_set:Nn \l__diagbox_ya_fp
      { \dim_to_fp:n { \ht \diagbox@boxa + \dp \diagbox@boxa } }
    \fp_set:Nn \l__diagbox_xb_fp
      { \dim_to_fp:n { \wd \diagbox@boxb } }
    \fp_set:Nn \l__diagbox_yb_fp
      { \dim_to_fp:n { \ht \diagbox@boxb + \dp \diagbox@boxb } }
    \fp_set:Nn \l__diagbox_xm_fp
      { \dim_to_fp:n { \wd \diagbox@boxm } }
    \fp_set:Nn \l__diagbox_ym_fp
      { \dim_to_fp:n { \ht \diagbox@boxm + \dp \diagbox@boxm } }
    \fp_set:Nn \l__diagbox_s_fp { \l__diagbox_xb_fp + \l__diagbox_xm_fp }
    \fp_set:Nn \l__diagbox_t_fp { \l__diagbox_ya_fp + \l__diagbox_ym_fp }
    \fp_set_eq:NN \l__diagbox_delta_fp \c_nan_fp
    \dim_compare:nNnTF \diagbox@wd = \c_zero_dim
      { \__diagbox_calculate_width: }
      { \fp_set:Nn \l__diagbox_x_fp { \dim_to_fp:n { \diagbox@wd } } }
    \dim_compare:nNnTF \diagbox@ht = \c_zero_dim
      { \__diagbox_calculate_height: }
      { \fp_set:Nn \l__diagbox_y_fp { \dim_to_fp:n { \diagbox@ht } } }
    \edef \x   { \fp_use:N \l__diagbox_x_fp }
    \edef \y   { \fp_use:N \l__diagbox_y_fp }
    \edef \xm  { \fp_use:N \l__diagbox_xm_fp }
    \edef \ym  { \fp_use:N \l__diagbox_ym_fp }
    \edef \xxm { \fp_eval:n { \l__diagbox_x_fp - \l__diagbox_xm_fp } }
    \edef \yym { \fp_eval:n { \l__diagbox_y_fp - \l__diagbox_ym_fp } }
  }
\cs_new_protected:Npn \__diagbox_calculate_width:
  {
    \fp_zero:N \l__diagbox_x_fp
    \fp_compare:nNnT \l__diagbox_yb_fp < \l__diagbox_t_fp
      {
        \__diagbox_calculate_coefficient:
        \fp_if_nan:nF { \l__diagbox_sqrt_fp }
          {
            \fp_set:Nn \l__diagbox_x_fp
              {
                ( \l__diagbox_u_fp + \l__diagbox_v_fp + \l__diagbox_sqrt_fp ) /
                ( 2 ( \l__diagbox_t_fp - \l__diagbox_yb_fp ) )
              }
          }
      }
    \fp_compare:nNnF \l__diagbox_x_fp > \c_zero_fp
      {
        \fp_set:Nn \l__diagbox_x_fp
          { 2 ( max( \l__diagbox_xa_fp , \l__diagbox_xb_fp ) + \l__diagbox_xm_fp ) }
        \msg_warning:nnxx { diagbox } { calculate-error }
          { width } { \fp_use:N \l__diagbox_x_fp }
      }
    \diagbox@wd = \fp_to_dim:N \l__diagbox_x_fp \scan_stop:
  }
\cs_new_protected:Npn \__diagbox_calculate_height:
  {
    \fp_zero:N \l__diagbox_y_fp
    \fp_compare:nNnT \l__diagbox_xa_fp < \l__diagbox_s_fp
      {
        \__diagbox_calculate_coefficient:
        \fp_if_nan:nF { \l__diagbox_sqrt_fp }
          {
            \fp_set:Nn \l__diagbox_y_fp
              {
                ( \l__diagbox_u_fp - \l__diagbox_v_fp - \l__diagbox_sqrt_fp ) /
                ( 2 ( \l__diagbox_xa_fp - \l__diagbox_s_fp ) )
              }
          }
      }
    \fp_compare:nNnF \l__diagbox_y_fp > \c_zero_fp
      {
        \fp_set:Nn \l__diagbox_y_fp
          { 2 ( max( \l__diagbox_ya_fp , \l__diagbox_yb_fp ) + \l__diagbox_ym_fp ) }
        \msg_warning:nnxx { diagbox } { calculate-error }
          { height } { \fp_use:N \l__diagbox_y_fp }
      }
    \diagbox@ht = \fp_to_dim:N \l__diagbox_y_fp \scan_stop:
  }
\cs_new_protected:Npn \__diagbox_calculate_coefficient:
  {
    \fp_if_nan:nT { \l__diagbox_delta_fp }
      { \__diagbox_calculate_coefficient_aux: }
  }
\cs_new_protected:Npn \__diagbox_calculate_coefficient_aux:
  {
    \fp_set:Nn \l__diagbox_u_fp
      {
        \l__diagbox_xa_fp * \l__diagbox_ym_fp -
        \l__diagbox_xm_fp * \l__diagbox_yb_fp
      }
    \fp_set:Nn \l__diagbox_v_fp
      {
        \l__diagbox_s_fp * \l__diagbox_t_fp -
        \l__diagbox_xa_fp * \l__diagbox_yb_fp
      }
    \fp_set:Nn \l__diagbox_delta_fp
      {
        ( \l__diagbox_u_fp + \l__diagbox_v_fp )^2 +
        4 * \l__diagbox_xa_fp * ( \l__diagbox_t_fp - \l__diagbox_yb_fp ) *
          ( \l__diagbox_xm_fp * ( \l__diagbox_yb_fp - \l__diagbox_ym_fp ) -
            \l__diagbox_xb_fp * \l__diagbox_ym_fp )
      }
    \fp_compare:nNnTF \l__diagbox_delta_fp < \c_zero_fp
      { \fp_set_eq:NN \l__diagbox_sqrt_fp \c_nan_fp }
      { \fp_set:Nn \l__diagbox_sqrt_fp { sqrt(\l__diagbox_delta_fp) } }
  }
\cs_new_eq:NN \diagbox@solve@equations \__diagbox_solve_equations:
\fp_new:N \l__diagbox_xa_fp
\fp_new:N \l__diagbox_ya_fp
\fp_new:N \l__diagbox_xb_fp
\fp_new:N \l__diagbox_yb_fp
\fp_new:N \l__diagbox_xm_fp
\fp_new:N \l__diagbox_ym_fp
\fp_new:N \l__diagbox_x_fp
\fp_new:N \l__diagbox_y_fp
\fp_new:N \l__diagbox_s_fp
\fp_new:N \l__diagbox_t_fp
\fp_new:N \l__diagbox_u_fp
\fp_new:N \l__diagbox_v_fp
\fp_new:N \l__diagbox_sqrt_fp
\fp_new:N \l__diagbox_delta_fp
\msg_new:nnn { diagbox } { calculate-error }
  {
    Cannot~calculate~proper~#1~of~triple~diagbox~
    \msg_line_context:. \\
    Use~#2pt~instead.
  }
\file_input_stop:
\fi
\RequirePackage{fp}
\FPmessagesfalse
\def\diagbox@solve@equations{%
  \edef\xa{\strip@pt\wd\diagbox@boxa}%
  \edef\ya{\strip@pt\dimexpr\ht\diagbox@boxa+\dp\diagbox@boxa\relax}%
  \edef\xb{\strip@pt\wd\diagbox@boxb}%
  \edef\yb{\strip@pt\dimexpr\ht\diagbox@boxb+\dp\diagbox@boxb\relax}%
  \edef\xm{\strip@pt\wd\diagbox@boxm}%
  \edef\ym{\strip@pt\dimexpr\ht\diagbox@boxm+\dp\diagbox@boxm\relax}%
  \FPneg\bi\yb
  \FPadd\ci\xb\xm  \FPneg\ci\ci
  \FPmul\di\xm\yb
  \FPadd\bj\ya\ym  \FPneg\bj\bj
  \FPneg\cj\xa
  \FPmul\dj\xa\ym
  \FPsub\u\dj\di
  \FPupn{v}{bj ci * bi cj * -}%
  \FPupn{delta}{bi dj * bj di * - cj ci - * 4 * v u + copy * -}%
  \newif\ifdeltapositive
  \FPifneg\delta \deltapositivefalse \else \deltapositivetrue \fi
  \FPset\x{0}%
  \FPset\y{0}%
  \ifdim\diagbox@wd=\z@
    \ifdim\bi\p@>\bj\p@\ifdeltapositive
      \FPupn{x}{2 bj bi - 2 delta root v u - + / /}%
    \fi\fi
    \ifdim\x\p@=\z@
      \FPupn{x}{xa xm + xb xm + max 2 *}%
      \PackageWarning{diagbox}{Cannot calculate proper width of triple diagbox.\MessageBreak
        Use \x pt instead.}%
    \fi
    \diagbox@wd=\x\p@
  \else
    \edef\x{\strip@pt\diagbox@wd}%
  \fi
  \ifdim\diagbox@ht=\z@
    \ifdim\ci\p@<\cj\p@\ifdeltapositive
      \FPupn{y}{2 cj ci - 2 delta root v u + - / /}%
    \fi\fi
    \ifdim\y\p@=\z@
      \FPupn{y}{ya ym + yb ym + max 2 *}%
      \PackageWarning{diagbox}{Cannot calculate proper height of triple diagbox.\MessageBreak
        Use \y pt instead.}%
    \fi
    \diagbox@ht=\y\p@
  \else
    \edef\y{\strip@pt\diagbox@ht}%
  \fi
  \FPsub\xxm\x\xm
  \FPsub\yym\y\ym
}
\endinput
%%
%% End of file `diagbox.sty'.
