Debian Codegraph @

texmf-dist/doc/latex/sdaps/html/_sources/sdapsarray.rst.txt

raw
1 sdapsarray package
2 ==================
3
4 This is a base package for "array" like environments. It really is similar to a
5 tabularx environment to some extend. Its purpose is much more specialized compared
6 to tabularx. It is less flexible in the types of layouts that can be realized but
7 a lot more powerful otherwise. The `sdapsarray` environment has the following
8 features:
9
10 * All :environ:`sdapsarray` environments in the document can be aligned to each other
11 * The environment can span multiple pages
12 * Headers will be repeated when page splits are encountered
13 * The rows/columns can be swapped on the fly
14 * Different ``layouter`` can be plugged in to modify the rendering
15 * Fragile content can be used without further preparation
16 * Contained content is executed exactly once (important for metadata generation)
17
18 Things that are *not* possible currently:
19
20 * Row or column backgrounds
21 * Grid lines
22
23 .. warning::
24 The :environ:`sdapsarray` is **not** a ``tabular`` like environment. It behaves
25 in similar ways, but there are fundamental differences, causing some issues:
26
27 * You **must not** add a trailing ``\\`` to the last row.
28
29 .. sdaps:: Example of a sdapsarray environment
30
31 The following two \texttt{sdapsarray} environments are almost identical. They
32 are both aligned to each other because the \texttt{align} option is set to
33 the same value. In the second environment the rows and columnes are swapped
34 by setting the \texttt{flip} option.
35
36 \begin{sdapsarray}[align=testing]
37 row header & colum header & colum header \\
38 row header & cell 1 & cell 2 \\
39 row header & cell 3 & cell 4
40 \end{sdapsarray}
41
42 \hrule
43
44 \begin{sdapsarray}[flip,align=testing]
45 row header & colum header & colum header \\
46 row header & cell 1 & cell 2 \\
47 row header & cell 3 & cell 4
48 \end{sdapsarray}
49
50 .. sdaps:: Example of a sdapsarray environment split over two columns using multicols
51 :preamble: \usepackage{multicol}
52
53 \begin{multicols}{2}
54 \begin{sdapsarray}[align=testing,layouter=rotated]
55 colum header 0 & colum header 1 & colum header 2 \\
56 row header 1 & cell 1 & cell 2 \\
57 row header 2 & cell 3 & cell 4 \\
58 row header 3 & cell 5 & cell 6 \\
59 row header 4 & cell 7 & cell 8 \\
60 row header 5 & cell 9 & cell 10 \\
61 row header 6 & cell 11 & cell 12
62 \end{sdapsarray}
63 \end{multicols}
64
65
66 Layout and formatting considerations
67 ------------------------------------
68
69 The following hold true inside the environment:
70
71 * The row headers are set into a :macro:`\\vtop` with the left over width from
72 the cells. This vertical box is later re-set into a :macro:`\\vbox`. The
73 effect is that the interrow skip is calculated between the last element of
74 the previous row and the first element of the next row. this means you must
75 be careful to not insert invisible content at the start of the vertical box.
76 (e.g. by adding a :macro:`\\leavevmode`).
77 * The exception to the above rule is the start of the environment (i.e. the
78 header row) for which the top baseline information is (currently) discarded!
79 * Each cell is set into an :macro:`\\hbox` with the last skip in the box removed
80 again (i.e. trailing space). You can use :macro:`\\hfill` to align the box to
81 the left/right but need to prevent the :macro:`\\hfill` to be removed again
82 for left alignment (e.g. by adding a ``\kern 0pt``).
83 * Column headers behave like cells but a special layouter can be assigned to
84 them.
85 * Row headers and column headers will usually be set on a common baseline. The
86 exception to this is if the column header contains multiple boxes/lines. In
87 that case the cells will be centered ignoring the baselines of both cells
88 and row header.
89 * A penalty of 10 is inserted between rows.
90
91
92 sdapsarray environment
93 ----------------------
94
95 .. environ::
96 \begin{sdapsarray}[kwargs]
97 content with cells delimitted with & and \\
98 \end{sdapsarray}
99
100 :kwarg flip: Transpose array making rows to columns (default: ``false``)
101 :kwarg layouter: The layouter to use. New layouters can be defined, the following
102 exists by default:
103
104 * ``default``: Simple layout centering cells and giving all leftover space to the row
105 header which will line break automatically (this is the default)
106 * ``rotated``: Similar to default but rotates the column headers
107
108 :kwarg angle: The angle of the header when in ``rotated`` mode
109 :kwarg align: An arbitrary string to align multiple :environ:`sdapsarray` environments
110 to each other. All environments with the same string will be
111 aligned. (default: no alignment)
112 :kwarg keepenv: Do not modify the parser to consume ``&`` and ``\\`` for alignment.
113 Instead, the user must use :macro:`\\sdaps_array_alignment:` and :macro:`\\sdaps_array_newline:`.
114 This is only useful for writing custom environments which use :environ:`sdapsarray` internally.
115 Normal users should simply put any nested `array` environment into :macro:`\\sdapsnested`
116 to prevent issues (see below).
117 :kwarg no_header: Disable column header handling and repeating. Note that this
118 setting is independent of whether the ``flip`` option is set. As such, one may
119 need to take its value into account when setting it. (default: ``false``)
120 :kwarg colsep: Spacing added on the left/right of every cell. This defaults to `6pt`.
121 :kwarg rowsep: Extra spacing added between rows. This defaults to `0pt`.
122
123 The ``keepenv`` option should usually not be used by an end user writing a document, it is very useful
124 when writing environments which use :environ:`sdapsarray` internally (like :environ:`choicearray`).
125
126 .. macro:: \sdapsnested{content}
127
128 Reverts the ``&`` and ``\\`` to their original meaning. Content in an
129 :environ:`sdapsarray` environment can be wrapped with this if it requires
130 these characters to be active (i.e. you can use the ``array`` environment
131 this way for example).
132
133 .. macro:: \sdaps_array_alignment:
134
135 Alternative to using the ``&`` delimiter between cells. This is useful together
136 with the ``keepenv`` kwarg argument. In particular when creating custom environments
137 which use sdapsarray internally.
138
139 .. macro:: \sdaps_array_newline:
140
141 Alternative to using the ``\\`` delimiter between cells. This is useful together
142 with the ``keepenv`` kwarg argument. In particular when creating custom environments
143 which use sdapsarray internally.
144
145 .. sdaps:: Two sdapsarray environments each with a nested array, in one case using the keepenv option.
146 :preamble:
147 \usepackage{multicol}
148 % Wrap the commands with _ as we cannot use them directly. This needs to
149 % be a \def and not a \let because they are redefined dynamically internally.
150 \ExplSyntaxOn
151 \def\sdapsalignment{\sdaps_array_alignment:}
152 \def\sdapsnewline{\sdaps_array_newline:}
153 \ExplSyntaxOff
154
155 \begin{multicols}{2}
156 \begin{sdapsarray}
157 & col 1 & col 2 \\
158 row header 1 & \sdapsnested{$ \begin{array}{cc} a & b \\ c & d \end{array}$} & cell 2 \\
159 \verb^row_header^ & cell 3 & cell 4
160 \end{sdapsarray}
161
162 \begin{sdapsarray}[keepenv]
163 \sdapsalignment col 1 \sdapsalignment col 2 \sdapsnewline
164 row header 1 \sdapsalignment $ \begin{array}{cc} a & b \\ c & d \end{array}$ \sdapsalignment cell 2 \sdapsnewline
165 \verb^row_header^ \sdapsalignment cell 3 \sdapsalignment cell 4
166 \end{sdapsarray}
167 \end{multicols}
168
169
170 Defining a custom layouter
171 --------------------------
172
173 .. warning:: This is an advanced feature and its use a good or even in depth knowledge of how TeX processes boxes and input!
174
175 It is possible to register further ``layouter``
176 which can subsequently used throughout the document. These layouters need to
177 adhere to a number of rules which will not be explained in detail here.
178
179 The following code is a copy of the two predefined layouter not showing the
180 implementation of the different macros. Visible here is that they only differ
181 in the method to render the column header ``colhead``, all other methods are
182 identical.
183
184 .. code::
185
186 \prop_gput:Nnn \g__sdaps_array_layouter_prop { default } {
187 begin = { \_sdaps_array_begin_default: },
188 row_start = { \_sdaps_array_row_start_default: },
189 rowhead = { \_sdaps_array_rowhead_default:Nw },
190 colhead = { \_sdaps_array_cell_default:Nw },
191 cell = { \_sdaps_array_cell_default:Nw },
192 row = { \_sdaps_array_row_ltr:NNNN },
193 end = { \_sdaps_array_end_default: },
194 }
195
196 \prop_gput:Nnn \g__sdaps_array_layouter_prop { rotated } {
197 begin = { \_sdaps_array_begin_default: },
198 row_start = { \_sdaps_array_row_start_default: },
199 rowhead = { \_sdaps_array_rowhead_default:Nw },
200 colhead = { \_sdaps_array_cell_rotated:Nw },
201 cell = { \_sdaps_array_cell_default:Nw },
202 row = { \_sdaps_array_row_ltr:NNNN },
203 end = { \_sdaps_array_end_default: },
204 }
205
206 If you consider modifying the layouter, then please have a look at the relevant
207 parts of ``sdapsarray.dtx``. Also, please consider submitting modifications for
208 upstream inclusion so that other people can benefit from new features.
209