elog2labfolder/_build/latex/sphinxmulticell.sty
author weiher
Thu, 11 Jan 2018 12:10:42 +0100
changeset 3 b71be85a294c
permissions -rw-r--r--
Initial commit of labfolder at FHI documentation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
     1
\NeedsTeXFormat{LaTeX2e}
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
     2
\ProvidesPackage{sphinxmulticell}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
     3
    [2017/02/23 v1.6 better span rows and columns of a table (Sphinx team)]%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
     4
\DeclareOption*{\PackageWarning{sphinxmulticell}{Option `\CurrentOption' is unknown}}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
     5
\ProcessOptions\relax
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
     6
%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
     7
% --- MULTICOLUMN ---
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
     8
% standard LaTeX's \multicolumn
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
     9
% 1. does not allow verbatim contents,
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    10
% 2. interacts very poorly with tabulary.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    11
%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    12
% It is needed to write own macros for Sphinx: to allow code-blocks in merged
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    13
% cells rendered by tabular/longtable, and to allow multi-column cells with
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    14
% paragraphs to be taken into account sanely by tabulary algorithm for column
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    15
% widths.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    16
%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    17
% This requires quite a bit of hacking. First, in Sphinx, the multi-column
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    18
% contents will *always* be wrapped in a varwidth environment. The issue
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    19
% becomes to pass it the correct target width. We must trick tabulary into
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    20
% believing the multicolumn is simply separate columns, else tabulary does not
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    21
% incorporate the contents in its algorithm. But then we must clear the
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    22
% vertical rules...
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    23
%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    24
% configuration of tabulary
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    25
\setlength{\tymin}{3\fontcharwd\font`0 }% minimal width of "squeezed" columns
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    26
\setlength{\tymax}{10000pt}% allow enough room for paragraphs to "compete"
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    27
% we need access to tabulary's final computed width. \@tempdima is too volatile
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    28
% to hope it has kept tabulary's value when \sphinxcolwidth needs it.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    29
\newdimen\sphinx@TY@tablewidth
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    30
\def\tabulary{%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    31
  \def\TY@final{\sphinx@TY@tablewidth\@tempdima\tabular}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    32
  \let\endTY@final\endtabular
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    33
  \TY@tabular}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    34
% next hack is needed only if user has set latex_use_latex_multicolumn to True:
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    35
% it fixes tabulary's bug with \multicolumn defined "short" in first pass. (if
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    36
% upstream tabulary adds a \long, our extra one causes no harm)
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    37
\def\sphinx@tempa #1\def\multicolumn#2#3#4#5#6#7#8#9\sphinx@tempa
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    38
   {\def\TY@tab{#1\long\def\multicolumn####1####2####3{\multispan####1\relax}#9}}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    39
\expandafter\sphinx@tempa\TY@tab\sphinx@tempa
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    40
%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    41
% TN. 1: as \omit is never executed, Sphinx multicolumn does not need to worry
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    42
% like standard multicolumn about |l| vs l|. On the other hand it assumes
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    43
% columns are separated by a | ... (if not it will add extraneous
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    44
% \arrayrulewidth space for each column separation in its estimate of available
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    45
% width).
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    46
%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    47
% TN. 1b: as Sphinx multicolumn uses neither \omit nor \span, it can not
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    48
% (easily) get rid of extra macros from >{...} or <{...} between columns. At
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    49
% least, it has been made compatible with colortbl's \columncolor.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    50
%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    51
% TN. 2: tabulary's second pass is handled like tabular/longtable's single
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    52
% pass, with the difference that we hacked \TY@final to set in
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    53
% \sphinx@TY@tablewidth the final target width as computed by tabulary. This is
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    54
% needed only to handle columns with a "horizontal" specifier: "p" type columns
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    55
% (inclusive of tabulary's LJRC) holds the target column width in the
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    56
% \linewidth dimension.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    57
%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    58
% TN. 3: use of \begin{sphinxmulticolumn}...\end{sphinxmulticolumn} mark-up
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    59
% would need some hacking around the fact that groups can not span across table
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    60
% cells (the code does inserts & tokens, see TN1b). It was decided to keep it
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    61
% simple with \sphinxstartmulticolumn...\sphinxstopmulticolumn.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    62
%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    63
% MEMO about nesting: if sphinxmulticolumn is encountered in a nested tabular
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    64
% inside a tabulary it will think to be at top level in the tabulary. But
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    65
% Sphinx generates no nested tables, and if some LaTeX macro uses internally a
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    66
% tabular this will not have a \sphinxstartmulticolumn within it!
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    67
%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    68
\def\sphinxstartmulticolumn{%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    69
    \ifx\equation$% $ tabulary's first pass
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    70
        \expandafter\sphinx@TYI@start@multicolumn
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    71
    \else % either not tabulary or tabulary's second pass
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    72
        \expandafter\sphinx@start@multicolumn
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    73
    \fi
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    74
}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    75
\def\sphinxstopmulticolumn{%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    76
    \ifx\equation$% $ tabulary's first pass
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    77
        \expandafter\sphinx@TYI@stop@multicolumn
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    78
    \else % either not tabulary or tabulary's second pass
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    79
        \ignorespaces
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    80
    \fi
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    81
}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    82
\def\sphinx@TYI@start@multicolumn#1{%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    83
    % use \gdef always to avoid stack space build up
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    84
    \gdef\sphinx@tempa{#1}\begingroup\setbox\z@\hbox\bgroup
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    85
}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    86
\def\sphinx@TYI@stop@multicolumn{\egroup % varwidth was used with \tymax
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    87
    \xdef\sphinx@tempb{\the\dimexpr\wd\z@/\sphinx@tempa}% per column width
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    88
    \endgroup
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    89
    \expandafter\sphinx@TYI@multispan\expandafter{\sphinx@tempa}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    90
}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    91
\def\sphinx@TYI@multispan #1{%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    92
    \kern\sphinx@tempb\ignorespaces % the per column occupied width
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    93
    \ifnum#1>\@ne % repeat, taking into account subtleties of TeX's & ...
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    94
      \expandafter\sphinx@TYI@multispan@next\expandafter{\the\numexpr#1-\@ne\expandafter}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    95
    \fi
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    96
}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    97
\def\sphinx@TYI@multispan@next{&\relax\sphinx@TYI@multispan}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    98
%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    99
% Now the branch handling either the second pass of tabulary or the single pass
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   100
% of tabular/longtable. This is the delicate part where we gather the
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   101
% dimensions from the p columns either set-up by tabulary or by user p column
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   102
% or Sphinx \X, \Y columns. The difficulty is that to get the said width, the
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   103
% template must be inserted (other hacks would be horribly complicated except
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   104
% if we rewrote crucial parts of LaTeX's \@array !) and we can not do
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   105
% \omit\span like standard \multicolumn's easy approach. Thus we must cancel
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   106
% the \vrule separators. Also, perhaps the column specifier is of the l, c, r
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   107
% type, then we attempt an ad hoc rescue to give varwidth a reasonable target
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   108
% width.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   109
\def\sphinx@start@multicolumn#1{%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   110
    \gdef\sphinx@multiwidth{0pt}\gdef\sphinx@tempa{#1}\sphinx@multispan{#1}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   111
}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   112
\def\sphinx@multispan #1{%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   113
    \ifnum#1=\@ne\expandafter\sphinx@multispan@end
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   114
            \else\expandafter\sphinx@multispan@next
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   115
    \fi {#1}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   116
}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   117
\def\sphinx@multispan@next #1{%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   118
    % trick to recognize L, C, R, J or p, m, b type columns
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   119
    \ifdim\baselineskip>\z@
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   120
       \gdef\sphinx@tempb{\linewidth}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   121
    \else
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   122
    % if in an l, r, c type column, try and hope for the best
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   123
       \xdef\sphinx@tempb{\the\dimexpr(\ifx\TY@final\@undefined\linewidth\else
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   124
            \sphinx@TY@tablewidth\fi-\arrayrulewidth)/\sphinx@tempa
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   125
            -\tw@\tabcolsep-\arrayrulewidth\relax}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   126
    \fi
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   127
    \noindent\kern\sphinx@tempb\relax
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   128
    \xdef\sphinx@multiwidth
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   129
           {\the\dimexpr\sphinx@multiwidth+\sphinx@tempb+\tw@\tabcolsep+\arrayrulewidth}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   130
    % hack the \vline and the colortbl macros
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   131
    \sphinx@hack@vline\sphinx@hack@CT&\relax
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   132
    % repeat
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   133
    \expandafter\sphinx@multispan\expandafter{\the\numexpr#1-\@ne}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   134
}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   135
% packages like colortbl add group levels, we need to "climb back up" to be
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   136
% able to hack the \vline and also the colortbl inserted tokens. This creates
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   137
% empty space whether or not the columns were | separated:
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   138
\def\sphinx@hack@vline{\ifnum\currentgrouptype=6\relax
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   139
    \kern\arrayrulewidth\arrayrulewidth\z@\else\aftergroup\sphinx@hack@vline\fi}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   140
\def\sphinx@hack@CT{\ifnum\currentgrouptype=6\relax
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   141
    \let\CT@setup\sphinx@CT@setup\else\aftergroup\sphinx@hack@CT\fi}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   142
% It turns out \CT@row@color is not expanded contrarily to \CT@column@color
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   143
% during LaTeX+colortbl preamble preparation, hence it would be possible for
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   144
% \sphinx@CT@setup to discard only the column color and choose to obey or not
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   145
% row color and cell color. It would even be possible to propagate cell color
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   146
% to row color for the duration of the Sphinx multicolumn... the (provisional?)
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   147
% choice has been made to cancel the colortbl colours for the multicolumn
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   148
% duration.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   149
\def\sphinx@CT@setup #1\endgroup{\endgroup}% hack to remove colour commands
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   150
\def\sphinx@multispan@end#1{%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   151
    % first, trace back our steps horizontally
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   152
    \noindent\kern-\dimexpr\sphinx@multiwidth\relax
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   153
    % and now we set the final computed width for the varwidth environment
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   154
    \ifdim\baselineskip>\z@
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   155
       \xdef\sphinx@multiwidth{\the\dimexpr\sphinx@multiwidth+\linewidth}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   156
    \else
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   157
       \xdef\sphinx@multiwidth{\the\dimexpr\sphinx@multiwidth+
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   158
         (\ifx\TY@final\@undefined\linewidth\else
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   159
          \sphinx@TY@tablewidth\fi-\arrayrulewidth)/\sphinx@tempa
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   160
          -\tw@\tabcolsep-\arrayrulewidth\relax}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   161
    \fi
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   162
    % we need to remove colour set-up also for last cell of the multi-column
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   163
    \aftergroup\sphinx@hack@CT
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   164
}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   165
\newcommand*\sphinxcolwidth[2]{%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   166
  % this dimension will always be used for varwidth, and serves as maximum
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   167
  % width when cells are merged either via multirow or multicolumn or both,
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   168
  % as always their contents is wrapped in varwidth environment.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   169
  \ifnum#1>\@ne % multi-column (and possibly also multi-row)
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   170
  % we wrote our own multicolumn code especially to handle that (and allow
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   171
  % verbatim contents)
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   172
   \ifx\equation$%$
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   173
       \tymax % first pass of tabulary (cf MEMO above regarding nesting)
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   174
   \else % the \@gobble thing is for compatibility with standard \multicolumn
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   175
       \sphinx@multiwidth\@gobble{#1/#2}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   176
   \fi
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   177
  \else % single column multirow
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   178
   \ifx\TY@final\@undefined % not a tabulary.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   179
    \ifdim\baselineskip>\z@
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   180
        % in a p{..} type column, \linewidth is the target box width
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   181
        \linewidth
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   182
    \else
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   183
        % l, c, r columns. Do our best.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   184
        \dimexpr(\linewidth-\arrayrulewidth)/#2-
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   185
                \tw@\tabcolsep-\arrayrulewidth\relax
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   186
    \fi
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   187
   \else % in tabulary
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   188
    \ifx\equation$%$% first pass
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   189
        \tymax % it is set to a big value so that paragraphs can express themselves
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   190
    \else
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   191
     % second pass.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   192
     \ifdim\baselineskip>\z@
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   193
         \linewidth % in a L, R, C, J column or a p, \X, \Y ...
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   194
     \else
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   195
         % we have hacked \TY@final to put in \sphinx@TY@tablewidth the table width
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   196
         \dimexpr(\sphinx@TY@tablewidth-\arrayrulewidth)/#2-
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   197
                 \tw@\tabcolsep-\arrayrulewidth\relax
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   198
     \fi
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   199
    \fi
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   200
   \fi
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   201
  \fi
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   202
}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   203
% fallback default in case user has set latex_use_latex_multicolumn to True:
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   204
% \sphinxcolwidth will use this only inside LaTeX's standard \multicolumn
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   205
\def\sphinx@multiwidth #1#2{\dimexpr % #1 to gobble the \@gobble (!)
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   206
    (\ifx\TY@final\@undefined\linewidth\else\sphinx@TY@tablewidth\fi
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   207
     -\arrayrulewidth)*#2-\tw@\tabcolsep-\arrayrulewidth\relax}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   208
%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   209
% --- MULTIROW ---
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   210
% standard \multirow
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   211
% 1. does not allow verbatim contents,
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   212
% 2. does not allow blank lines in its argument,
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   213
% 3. its * specifier means to typeset "horizontally" which is very
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   214
%    bad for paragraph content. 2016 version has = specifier but it
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   215
%    must be used with p type columns only, else results are bad,
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   216
% 4. it requires manual intervention if the contents is too long to fit
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   217
%    in the asked-for number of rows.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   218
% 5. colour panels (either from \rowcolor or \columncolor) will hide
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   219
%    the bottom part of multirow text, hence manual tuning is needed
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   220
%    to put the multirow insertion at the _bottom_.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   221
%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   222
% The Sphinx solution consists in always having contents wrapped
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   223
% in a varwidth environment so that it makes sense to estimate how many
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   224
% lines it will occupy, and then ensure by insertion of suitable struts
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   225
% that the table rows have the needed height. The needed mark-up is done
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   226
% by LaTeX writer, which has its own id for the merged cells.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   227
%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   228
% The colour issue is solved by clearing colour panels in all cells,
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   229
% whether or not the multirow is single-column or multi-column.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   230
%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   231
% In passing we obtain baseline alignements across rows (only if
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   232
% \arraylinestretch is 1, as LaTeX's does not obey \arraylinestretch in "p"
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   233
% multi-line contents, only first and last line...)
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   234
%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   235
% TODO: examine the situation with \arraylinestretch > 1. The \extrarowheight
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   236
% is hopeless for multirow anyhow, it makes baseline alignment strictly
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   237
% impossible.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   238
\newcommand\sphinxmultirow[2]{\begingroup
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   239
  % #1 = nb of spanned rows, #2 = Sphinx id of "cell", #3 = contents
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   240
  % but let's fetch #3 in a way allowing verbatim contents !
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   241
  \def\sphinx@nbofrows{#1}\def\sphinx@cellid{#2}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   242
  \afterassignment\sphinx@multirow\let\next=
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   243
}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   244
\def\sphinx@multirow {%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   245
  \setbox\z@\hbox\bgroup\aftergroup\sphinx@@multirow\strut
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   246
}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   247
\def\sphinx@@multirow {%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   248
  % The contents, which is a varwidth environment, has been captured in
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   249
  % \box0 (a \hbox).
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   250
  % We have with \sphinx@cellid an assigned unique id. The goal is to give
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   251
  % about the same height to all the involved rows.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   252
  % For this Sphinx will insert a \sphinxtablestrut{cell_id} mark-up
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   253
  % in LaTeX file and the expansion of the latter will do the suitable thing.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   254
  \dimen@\dp\z@
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   255
  \dimen\tw@\ht\@arstrutbox
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   256
  \advance\dimen@\dimen\tw@
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   257
  \advance\dimen\tw@\dp\@arstrutbox
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   258
  \count@=\dimen@       % type conversion dim -> int
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   259
  \count\tw@=\dimen\tw@
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   260
  \divide\count@\count\tw@ % TeX division truncates
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   261
  \advance\dimen@-\count@\dimen\tw@
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   262
  % 1300sp is about 0.02pt. For comparison a rule default width is 0.4pt.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   263
  % (note that if \count@ holds 0, surely \dimen@>1300sp)
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   264
  \ifdim\dimen@>1300sp \advance\count@\@ne \fi
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   265
  % now \count@ holds the count L of needed "lines"
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   266
  % and \sphinx@nbofrows holds the number N of rows
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   267
  % we have L >= 1 and N >= 1
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   268
  % if L is a multiple of N, ... clear what to do !
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   269
  % else write L = qN + r, 1 <= r < N and we will
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   270
  % arrange for each row to have enough space for:
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   271
  %     q+1 "lines" in each of the first r rows
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   272
  %       q "lines" in each of the (N-r) bottom rows
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   273
  % for a total of (q+1) * r + q * (N-r) = q * N + r = L
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   274
  % It is possible that q == 0.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   275
  \count\tw@\count@
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   276
  % the TeX division truncates
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   277
  \divide\count\tw@\sphinx@nbofrows\relax
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   278
  \count4\count\tw@ % q
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   279
  \multiply\count\tw@\sphinx@nbofrows\relax
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   280
  \advance\count@-\count\tw@ % r
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   281
  \expandafter\xdef\csname sphinx@tablestrut_\sphinx@cellid\endcsname
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   282
     {\noexpand\sphinx@tablestrut{\the\count4}{\the\count@}{\sphinx@cellid}}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   283
  \dp\z@\z@
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   284
  % this will use the real height if it is >\ht\@arstrutbox
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   285
  \sphinxtablestrut{\sphinx@cellid}\box\z@
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   286
  \endgroup % group was opened in \sphinxmultirow
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   287
}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   288
\newcommand*\sphinxtablestrut[1]{%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   289
  % #1 is a "cell_id", i.e. the id of a merged group of table cells
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   290
  \csname sphinx@tablestrut_#1\endcsname
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   291
}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   292
% LaTeX typesets the table row by row, hence each execution can do
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   293
% an update for the next row.
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   294
\newcommand*\sphinx@tablestrut[3]{\begingroup
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   295
  % #1 = q, #2 = (initially) r, #3 = cell_id, q+1 lines in first r rows
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   296
  % if #2 = 0, create space for max(q,1) table lines
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   297
  % if #2 > 0, create space for q+1 lines and decrement #2
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   298
  \leavevmode
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   299
  \count@#1\relax
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   300
  \ifnum#2=\z@
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   301
    \ifnum\count@=\z@\count@\@ne\fi
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   302
  \else
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   303
    % next row will be with a #2 decremented by one
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   304
    \expandafter\xdef\csname sphinx@tablestrut_#3\endcsname
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   305
      {\noexpand\sphinx@tablestrut{#1}{\the\numexpr#2-\@ne}{#3}}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   306
   \advance\count@\@ne
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   307
  \fi
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   308
  \vrule\@height\ht\@arstrutbox
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   309
        \@depth\dimexpr\count@\ht\@arstrutbox+\count@\dp\@arstrutbox-\ht\@arstrutbox\relax
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   310
        \@width\z@
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   311
  \endgroup
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   312
  % we need this to avoid colour panels hiding bottom parts of multirow text
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   313
  \sphinx@hack@CT
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   314
}%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   315
\endinput
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   316
%%
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   317
%% End of file `sphinxmulticell.sty'.