From 7a8d1925127ad121a8f591db931524f9b8eacb93 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 28 Feb 2022 03:02:40 +0000 Subject: CTAN sync 202202280302 --- macros/luatex/generic/lutabulartools/README.md | 5 +- .../generic/lutabulartools/lutabulartools.lua | 177 +++++++++--------- .../generic/lutabulartools/lutabulartools.pdf | Bin 59544 -> 83452 bytes .../generic/lutabulartools/lutabulartools.sty | 102 ++++++----- .../generic/lutabulartools/lutabulartools.tex | 198 +++++++++++++++++---- 5 files changed, 316 insertions(+), 166 deletions(-) (limited to 'macros/luatex/generic/lutabulartools') diff --git a/macros/luatex/generic/lutabulartools/README.md b/macros/luatex/generic/lutabulartools/README.md index 90b5a86b15..ba443802b8 100644 --- a/macros/luatex/generic/lutabulartools/README.md +++ b/macros/luatex/generic/lutabulartools/README.md @@ -1,12 +1,13 @@ # lutabulartools -This LuaLaTeX package offers some useful macros for tabular matter. The `\MC` command it provides allows one to specify a multi-row and or multi-column cell with minimal syntax. The package loads `booktabs` and adds a gray midrule, and allows a user to specify multiple `\cmidrules` with one command. +This LuaLaTeX package offers some useful macros for tabular matter. The `\MC` command it provides allows one to specify a multi-row and or multi-column cell with minimal syntax. The package loads `booktabs` and adds a gray midrule, and allows a user to specify multiple `\cmidrules` with one command. The [github repo](https://github.com/kalekje/lutabulartools) has an MS Excel +macro-enabled spreadsheet named "LaTeX-Tabular-Generator.xlsm" to help make tables in LaTeX. # License (MIT) -Copyright (C) 2021 Kale Ewasiuk +Copyright (C) 2021-2022 Kale Ewasiuk Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/macros/luatex/generic/lutabulartools/lutabulartools.lua b/macros/luatex/generic/lutabulartools/lutabulartools.lua index ca6b1aa0b4..30165f89a9 100644 --- a/macros/luatex/generic/lutabulartools/lutabulartools.lua +++ b/macros/luatex/generic/lutabulartools/lutabulartools.lua @@ -1,6 +1,6 @@ --% Kale Ewasiuk (kalekje@gmail.com) ---% 2021-11-07 ---% Copyright (C) 2021 Kale Ewasiuk +--% 2022-02-27 +--% Copyright (C) 2021-2022 Kale Ewasiuk --% --% Permission is hereby granted, free of charge, to any person obtaining a copy --% of this software and associated documentation files (the "Software"), to deal @@ -24,31 +24,19 @@ local ltt = {} ---todo clean up the code, make some stuff local ---todo maybe add the penlight lua table to latex tabular? +ltt.col_spec1 = {} -- column spec if one column wide (since makcell nests a tabular, preserve col_spec below) +ltt.col_spec = {} -- tab column spec if above 1 +ltt.col = '' -- current column spec, single char, only applies to tabular with more than 1 column +ltt.col_num = 1 -- current column number ---integrate current cell ---todo check if S[] column cells work!!! ---todo might be smarter to just append this to tabular commands and read argument --- Initialize counter variable -ltt.NumTabCols = 0 -ltt.NumTabColsAbv = 0 -- num of tab columns if above 1 -ltt.TabColSpec = '' -ltt.TabColSpecAbv = '' -- tab column spec if above 1 -ltt.CurTabColAbv = '' -- current tab column spec if above 1 -ltt.TabColNum = 0 -ltt.NumBkts = 0 -ltt.NumTabColsMX = 0 - - ---todo re=enable local glue_t, unset_t, tabskip_st = node.id'glue', node.id'unset' local tabskip_st = table.swapped(node.subtypes'glue').tabskip assert(tabskip_st) -function ltt.get_TabColNum() +function ltt.set_col_num() + -- register current column info (column number and specification) local nest for i = tex.nest.ptr, 1, -1 do local tail = tex.nest[i].tail @@ -62,57 +50,32 @@ function ltt.get_TabColNum() for _, sub in node.traverse_id(unset_t, nest.head) do col = col + sub + 1 end - ltt.TabColNum = col + ltt.col_num = col else - ltt.TabColNum = 1 + ltt.col_num = 1 end - ltt.CurTabColAbv = ltt.TabColSpecAbv:sub(ltt.TabColNum,ltt.TabColNum) - ltt.NumTabColsMX = math.max(ltt.NumTabColsMX, ltt.TabColNum) -- a different way to calculate total cols - return ltt.TabColNum + ltt.col = ltt.col_spec[ltt.col_num] end -function ltt.get_TabRowNum() - return tex.count['c@RowNumCnt'] -- access latex counter -end - --- The next function computes the number of columns from --- contents of string 'zz' -function ltt.calc_NumTabCols( zz ) - --help_wrt(zz, 'col spec OG') - -- -- NOT NEEDED: zz = zz:gsub ( "^.-(%b{}).-$", "%1" ) -- retain the first "{....}" substring +function ltt.set_col_spec(zz) + -- contents of string 'zz' + -- register the table column specification zz = zz:gsub ( "%*%s-{(%d-)}%s-(%b{})" , -- expand expressions such as "*{5}{l}" to "lllll" function(y, z ) z = z:sub (2 , -2) return string.rep (z, y) end ) -- zz = zz:gsub ( "%b{}" , "" ) -- omit all stuff in curly braces and square zz = zz:gsub ( "%b[]" , "" ) zz = zz:gsub ( "[@!|><%s%*\']" , "" ) -- some more characters to ignore - -- todo: any columns defined that break into more than one column should be expanded here - --help_wrt(zz, 'col spec CLEAN') - ltt.TabColSpec = zz -- stripped column spec with no {} or < - ltt.NumTabCols = string.len(ltt.TabColSpec) - if ltt.NumTabCols > 1 then - ltt.TabColSpecAbv = ltt.TabColSpec - ltt.NumTabColsAbv = ltt.NumTabCols + zz = zz:gsub('%a', ltt.col_replaces) -- sub extra column + _col_spec = zz:totable() -- requires pl extras + --help_wrt(_col_spec, 'helpme') + if #_col_spec > 1 then + ltt.col_spec = _col_spec + else + ltt.col_spec1 = _col_spec end end ---todo fix square brackets after letters, expand multiple ---calc_NumTabCols('ss') ---calc_NumTabCols('*{6}{s}') ---calc_NumTabCols('l*{6}{l}') ---calc_NumTabCols('lll') ---calc_NumTabCols('ll[]') ---calc_NumTabCols('ll[]*{6}{l}') ---calc_NumTabCols('*{6}{l}') ---calc_NumTabCols('y*{6}{sq}x') ---print(_TabColSpec.. '<---Column spec') - ---http://ctan.mirror.rafal.ca/macros/latex/contrib/multirow/multirow.pdf ---http://ctan.mirror.colo-serv.net/macros/latex/contrib/makecell/makecell.pdf --- todo CONSIDER THIS --- https://tex.stackexchange.com/questions/331716/newline-in-multirow-environment - - --todo -- if p{} column, and multirow is 1, use {=} instead of {*} @@ -122,6 +85,8 @@ end function ltt.MagicCell(s0,spec,mcspec,pre,content) -- + ltt.set_col_num() -- register current column number and column spec + local STR = '' reset_bkt_cnt() @@ -132,8 +97,8 @@ function ltt.MagicCell(s0,spec,mcspec,pre,content) h, mcspec, c = ltt.get_HColSpec(h, mcspec, c) -- infer horizontal alignment, num columns --help_wrt(_CurTabColAbv,'current column') - if s0 == _xTrue or (pl.List({'S', 'Q', 'L', 'R'}):contains(ltt.CurTabColAbv) -- special columns for SI - and c == '') then -- multicolumn cannot have {} around it todo test with siunitx, num rows, num columns + if s0 == _xTrue or (pl.List(ltt.SI_cols):contains(ltt.col) -- special columns for SI + and c == '') then -- multicolumn cannot have {} around it STR = STR .. '{' -- multirow and makcell must have {} around it S column is used add_bkt_cnt() end @@ -167,7 +132,7 @@ end function ltt.parse_MagicCell_spec(spec) - local mrowsym = '*' + local mrowsym = '*' -- * = natural width, = will match p{2cm} for example local skipmakecell = false if string.find(spec, '=') then spec = spec:gsub('=', '') @@ -175,9 +140,9 @@ function ltt.parse_MagicCell_spec(spec) skipmakecell = true end - spec = spec:lower():gsub('%s','') -- take lower case and remove + spec = spec:lower():gsub('%s','') -- take lower case and remove space local vh, rc = spec:gextract('%a') -- extract characters - local v = vh:gfirst({'t', 'm', 'b'}) or 't' + local v = vh:gfirst({'t', 'm', 'b'}) or ltt.col_ver_repl[ltt.col] or 't' local h = vh:gfirst({'l', 'c', 'r'}) or '' v = v:gsub('m', 'c') @@ -191,50 +156,71 @@ function ltt.parse_MagicCell_spec(spec) end -ltt.TabColMapping = { -- horizontal cell alignment that multicolumn should use if () or [hori] not passed to func - l = 'l', - c = 'c', - r = 'r', - p = 'p', - P = 'c', - X = 'l', - Y = 'c', - Z = 'l', - N = 'c', - L = 'l', - R = 'r', - C = 'c', -} - function ltt.get_HColSpec(h, mcspec, c) -- take horizontal alignment -- c is num columns, h is horizontal alginment, --Assumes _TabColNum was calculated previosly - ltt.get_TabColNum() if c == '+' then -- fill row to end - c = tostring(ltt.NumTabColsAbv - ltt.TabColNum + 1) + c = tostring(#ltt.col_spec - ltt.col_num + 1) end if h == '' then -- if horizontal not provided, use declared column - h = ltt.TabColMapping[ltt.CurTabColAbv] or 'l' + h = ltt.col_hor_repl[ltt.col] or 'l' end if c ~= '' then -- only make new mcspec if column nums > 0 if mcspec == '' then -- and if no mcspec was passed mcspec = h - if ltt.TabColNum == 1 then -- if first column, auto detect padding + if ltt.col_num == 1 then -- if first column, auto detect padding mcspec = '@{}'..mcspec end - if (ltt.TabColNum + tonumber(c) - 1) == ltt.NumTabColsAbv then -- if end on last column + if (ltt.col_num + tonumber(c) - 1) == #ltt.col_spec then -- if end on last column mcspec = mcspec..'@{}' end else -- if mcspec if given, extract the alignment - ltt.calc_NumTabCols(mcspec) - h = ltt.TabColSpec -- get 1 character column spec from mcspec and override h + ltt.set_col_spec(mcspec) + h = ltt.col_spec1[1] -- get 1 character column spec from mcspec and override h end end return h, mcspec, c end --- midrule stuff + +ltt.col_ver_repl = { +m = 'm', +M = 'm', +b = 'b', +} + +ltt.col_hor_repl = { -- horizontal cell alignment that multicolumn should use if () or [hori] not passed to func + l = 'l', + c = 'c', + r = 'r', + p = 'l', + P = 'c', + X = 'l', + Y = 'c', + Z = 'l', + N = 'c', + L = 'l', + R = 'r', + C = 'c', +} + +-- allow user to place their own replacements in for a table, say if they define a column that expands to multiple +ltt.col_replaces = { +--x = 'lll' +} + +ltt.SI_cols = {'S', 'N', 'Q', 'L', 'R'} +--ltt.SI_cols = {'S'} +--ltt.SI_cols = {'N'} + + + + + +----- +--- midrule stuff +----- function ltt.get_midrule_col(s) if string.find(s, '+') then @@ -242,14 +228,11 @@ function ltt.get_midrule_col(s) if (s == '') or (s == '0') then s = 1 end - s = tostring(ltt.NumTabColsAbv - tonumber(s) + 1) -- use number of tabular columns above 0, + s = tostring(#ltt.col_spec - tonumber(s) + 1) -- use number of tabular columns above 0, end return s end ---todo if comma present, create multiple according to spec. Also allow LR in [] - ---- midrule stuff --- function ltt.make1cmidrule(s, r, c, cmd) -- s=square r=round c=curly cmd = '\\'..cmd @@ -283,4 +266,16 @@ function ltt.makecmidrules(s, r, c, cmd) end -return ltt -- lutabulartools \ No newline at end of file +--help_wrt('TEST COL ') +--for _, s in ipairs{ 'll', '*{6}{s}', 'l*{6}{l}', 'lll', 'll[]', 'll[]*{6}{l}', '*{6}{l}', 'y*{6}{sq}x', } do +-- ltt. set_col_spec(s) +-- help_wrt(ltt.col_spec,s) +--end + +return ltt -- lutabulartools + + + +--http://ctan.mirror.rafal.ca/macros/latex/contrib/multirow/multirow.pdf +--http://ctan.mirror.colo-serv.net/macros/latex/contrib/makecell/makecell.pdf +-- https://tex.stackexchange.com/questions/331716/newline-in-multirow-environment diff --git a/macros/luatex/generic/lutabulartools/lutabulartools.pdf b/macros/luatex/generic/lutabulartools/lutabulartools.pdf index 96488bd83a..770fb8045b 100644 Binary files a/macros/luatex/generic/lutabulartools/lutabulartools.pdf and b/macros/luatex/generic/lutabulartools/lutabulartools.pdf differ diff --git a/macros/luatex/generic/lutabulartools/lutabulartools.sty b/macros/luatex/generic/lutabulartools/lutabulartools.sty index b4eda9c3cf..bb72b660a8 100644 --- a/macros/luatex/generic/lutabulartools/lutabulartools.sty +++ b/macros/luatex/generic/lutabulartools/lutabulartools.sty @@ -1,6 +1,6 @@ % Kale Ewasiuk (kalekje@gmail.com) -% 2021-11-07 -% Copyright (C) 2021 Kale Ewasiuk +% 2022-02-27 +% Copyright (C) 2021-2022 Kale Ewasiuk % % Permission is hereby granted, free of charge, to any person obtaining a copy % of this software and associated documentation files (the "Software"), to deal @@ -23,7 +23,7 @@ % OR OTHER DEALINGS IN THE SOFTWARE. \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{lutabulartools}[2021-11-07] +\ProvidesPackage{lutabulartools}[2022-02-27] \RequirePackage{booktabs} \RequirePackage{multirow} @@ -38,12 +38,19 @@ \luadirect{lutabt = require('lutabulartools')} +\newcolumntype{\ltt@ltrim}{@{}} +\newcolumntype{\ltt@rtrim}{@{}} +\DeclareOption{notrim}{ + \newcolumntype{\ltt@ltrim}{} + \newcolumntype{\ltt@rtrim}{} +} -% DOES NOT WORK WITH colortbl package ??? %% adapted from % https://tex.stackexchange.com/questions/182953/add-midrule-every-5-lines-automatically +%% https://tex.stackexchange.com/questions/145084/what-is-the-function-of-noalign + \def\midruleXstep{5} \def\midruleXrule{\gmidrule} @@ -67,32 +74,18 @@ } \newcommand*{\resetmidruleX}{\setcounter{midruleX}{0}} %%% todo maybe put noalign in here - \resetmidruleX -%% https://tex.stackexchange.com/questions/145084/what-is-the-function-of-noalign -%\begin{tabular}{rclc@{\midruleX}} % inject midrule -%\toprule -%Number & Student Id & Name & Score\\\midrule\resetmidruleX % reset to 0 -%1 & 14-001 & Andy & 75 \\ -%2 & & & \\ -%3 & & & \\ -%4 & & & \\ -%5 & & & \\ -%6 & & & \\ -%7 & & & \\ -%8 & & & \\ -%9 & & & \\\resetmidruleX -%10 & & & \\%\noalign{\resetmidruleX} % noalig required to not cause error with bottomrule, but that's oka because it should be used on row 9 anyway -%\bottomrule -%\end{tabular} + %%%% %%% gray midrule and gray cmidrule - -\providecommand{\gmidrule}{\arrayrulecolor{lightgray}\specialrule{\lightrulewidth}{0.4\aboverulesep}{0.6\belowrulesep}\arrayrulecolor{black}} +\aboverulesep=0.0ex +\belowrulesep=0.5ex +\providecommand{\gmidrule}{\arrayrulecolor{lightgray}\specialrule{\lightrulewidth}{0.5\aboverulesep}{0.5\belowrulesep}\arrayrulecolor{black}} +\cmidrulewidth=\lightrulewidth %%% use gcmidrule for a gray "c" midrule % Copy \cmidrule from @@ -113,7 +106,7 @@ \global\advance\@cmidlb-\@cmidla \global\@thisrulewidth=#3 \@setrulekerning{#4} - \ifnum\@lastruleclass=\z@\vskip 0.4\aboverulesep\fi + \ifnum\@lastruleclass=\z@\vskip 0.5\aboverulesep\fi \ifnum0=`{\fi}\@gtempa \noalign{\ifnum0=`}\fi\futurenonspacelet\@tempa\@xgcmidrule} \def\@xgcmidrule{% @@ -123,7 +116,7 @@ \else \ifx\@tempa\morecmidrules \vskip \cmidrulesep \global\@lastruleclass=\@ne\else - \vskip 0.6\belowrulesep + \vskip 0.5\belowrulesep \global\@lastruleclass=\z@ \fi\fi \ifnum0=`{\fi} @@ -167,30 +160,17 @@ - - -%%% tabular commands - -\newcommand{\TabColNum}{\luadirect{tex.print(lutabt.get_TabColNum())}} % prints the current column number of tabular -\newcommand{\NumTabCols}{\luadirect{tex.print(lutabt.NumTabCols)}} % prints the total num columns of tabular -\newcounter{RowNumCnt} -\setcounter{RowNumCnt}{1} - \let\oldtabular\tabular \RenewExpandableDocumentCommand{\tabular}{ O{c} m }{% - \setcounter{RowNumCnt}{1}% - \luadirect{lutabt.calc_NumTabCols(\luastringN{#2})}% - \luadirect{lutabt.NumTabColsMX = 0}% fall back if calc doesnt work for some reason - \oldtabular[#1]{@{\stepcounter{RowNumCnt}}#2@{\luadirect{lutabt.get_TabColNum()}}}% + \luadirect{lutabt.set_col_spec(\luastringN{#2})}% + \oldtabular[#1]{\ltt@ltrim#2\ltt@rtrim}% } \expandafter\let\expandafter\oldtabulars\csname tabular*\endcsname \expandafter\let\expandafter\endoldtabulars\csname endtabular*\endcsname \RenewDocumentEnvironment{tabular*}{ m O{c} m }{% - \setcounter{RowNumCnt}{1}% - \luadirect{lutabt.calc_NumTabCols(\luastringN{#3})}% - \luadirect{lutabt.NumTabColsMX = 0}% fall back if calc doesnt work for some reason - \begin{oldtabulars}{#1}[#2]{@{\stepcounter{RowNumCnt}}#3@{\luadirect{lutabt.get_TabColNum()}}} + \luadirect{lutabt.set_col_spec(\luastringN{#3})}% + \begin{oldtabulars}{#1}[#2]{\ltt@ltrim#3\ltt@rtrim}% }{% \end{oldtabulars}% } @@ -211,7 +191,45 @@ )}} +\NewDocumentCommand{\setMCrepl}{m m}{\luadirect{ + lutabt.col_replaces.#1 = '#2' +}} +\NewDocumentCommand{\setMChordef}{ m m}{\luadirect{ + lutabt.col_hor_repl.#1 = '#2' +}} +\NewDocumentCommand{\setMCverdef}{ m m}{\luadirect{ + lutabt.col_ver_repl.#1 = '#2' +}} +\NewDocumentCommand{\addMCsicol}{ m }{\luadirect{ + lutabt.SI_cols[\string##lutabt.SI_cols+1] = '#1' +}} + \ProcessOptions + + + + + + +%%% OLD STUFF, +%% before I had a fall-back for counting columns (just calculate current column on last column once) +%% and kept track of row numbers. I felt that this wasn't needed, so I've removed. +%\newcommand{\TabColNum}{\luadirect{tex.print(lutabt.get_TabColNum())}} % prints the current column number of tabular +%\newcommand{\NumTabCols}{\luadirect{tex.print(lutabt.NumTabCols)}} % prints the total num columns of tabular +%\newcounter{RowNumCnt} +%\setcounter{RowNumCnt}{1} +% \setcounter{RowNumCnt}{1}% +% \luadirect{lutabt.NumTabColsMX = 0}% fall back if calc doesnt work for some reason +% \setcounter{RowNumCnt}{1}% +% \luadirect{lutabt.NumTabColsMX = 0}% fall back if calc doesnt work for some reason +%\DeclareOption{notrimx}{ +% \global\newcolumntype{\ltt@ltrim}{!{\stepcounter{RowNumCnt}}} +%% \global\newcolumntype{\ltt@rtrim}{!{\luadirect{lutabt.get_TabColNum()}}} +%} +%\DeclareOption{trimx}{ +% \newcolumntype{\ltt@ltrim}{@{\stepcounter{RowNumCnt}}} +%% \newcolumntype{\ltt@rtrim}{@{\luadirect{lutabt.get_TabColNum()}}} +%} diff --git a/macros/luatex/generic/lutabulartools/lutabulartools.tex b/macros/luatex/generic/lutabulartools/lutabulartools.tex index 65c7f2f694..54af32f78d 100644 --- a/macros/luatex/generic/lutabulartools/lutabulartools.tex +++ b/macros/luatex/generic/lutabulartools/lutabulartools.tex @@ -1,6 +1,6 @@ % Kale Ewasiuk (kalekje@gmail.com) -% 2021-11-07 -% Copyright (C) 2021 Kale Ewasiuk +% 2022-02-27 +% Copyright (C) 2021-2022 Kale Ewasiuk % % Permission is hereby granted, free of charge, to any person obtaining a copy % of this software and associated documentation files (the "Software"), to deal @@ -61,11 +61,20 @@ \title{lutabulartools} \subtitle{some useful tabular tools (LuaLaTeX-based)} +\usepackage{tabularx} +\usepackage{siunitx} + \begin{document} + +% todo: can improve naming... set col spec to a table instead of a string + + \maketitle lutabulartools is a package that contains a few useful macros to help with tables. -Most functions require LuaLaTeX. The following packages are loaded: +Most functions require LuaLaTeX. +This package redefines the {\ttfamily tabular} and {\ttfamily tabular*} environments. +The following packages are loaded: \texttt{ {booktabs}, {multirow}, @@ -78,51 +87,148 @@ Most functions require LuaLaTeX. The following packages are loaded: {penlight}, } +\section{Options} +The author likes tables with left and right-most columns flush to the end. +Since the \cmd{tabular} env is redefined in this, the author took the liberty to +automatically pad the \cmd{tabular} cell spec with \cmd{@{}} on each end. +If you don't want this, you can pass \cmd{notrim} to the package. Or, +you can manually fix it in a \cmd{tabular} with \cmd{!{}} like so: + +\begin{LTXexample} +\begin{tabular}{!{}c!{}}\toprule +Xyz\\\bottomrule \end{tabular} +\end{LTXexample} + + \section{\texttt{\textbackslash MC} -- Magic Cell} \texttt{\textbackslash MC} (magic cell) combines the facilities of \cmd{\multirow} and \cmd{\multicolumn} from the \texttt{multirow} package, and \cmd{\makcell} from the titular package. With the help of LuaLaTeX, it takes an easy-to-use cell specification and employs said commands as required. +\cmd{\MC} will not work properly if your table is only 1 column wide (you probably don't need \cmd{MC} in that case anyway...). Here is the usage: \texttt{\textbackslash MC * [cell spec] (override multicolumn col) \{contents\} } \llcmd{*}This will wrap the entire command in \{\}. This is necessary for \texttt{siunitx} single-column width columns. -However, the \tMC\ command attempts to detect this automatically. +However, the \cmd{\MC} command attempts to detect this automatically. \llcmd{[cell spec]}% Any letters placed in this argument are used for cell alignment. You can use one of three: \qcmd{t}, \qcmd{m}, \qcmd{b} for top, middle, bottom (vertical alignment), or \qcmd{l}, \qcmd{c}, \qcmd{r} for horizontal alignment. -By default, \tMC\ will try to autodetect the horizontal alignment based on the current column. +By default, \cmd{\MC} will try to autodetect the horizontal alignment based on the current column. If it can't, it will be left-aligned. -The default vertical alginment is top. +The default vertical alginment is top. More on this in section \ref{s.def}. This argument can also contain two integers, separated by a comma (if two are used). \qcmd{C,R}, \qcmd{C}, or \qcmd{,R} are a valid inputs, -where R=rows (int), and C=columns, (int). +where \cmd{R}=rows (int), and \cmd{C}=columns, (int). If you want a 1 column wide, multirow cell, -you can pass \qcmd{,R}. These numbers can be negative. -If no spec is passed, (argument empty), \tMC\ +you can pass \qcmd{,R}. These numbers can be negative (positive numbers occupy columns to the right +and rows below, and negative numbers occupy columns to the left and rows above). +If no spec is passed, (argument empty), \cmd{\MC} acts like a \texttt{makecell}. Additionally, you can pass \qcmd{+} in place of C (number of columns wide), and it will make the cell width fill until the end of the current row. Examples:\\ \qcmd{\MC[2,2]} means two columns wide, two rows tall.\\ -\qcmd{\MC[2,1]} or \qcmd{\MC[2]} or means two columns wide, one row tall.\\ +\qcmd{\MC[2,1]} or \qcmd{\MC[2]} means two columns wide, one row tall.\\ \qcmd{\MC[1,2]} or \qcmd{\MC[,2]} means one column wide, two rows tall.\\ +\qcmd{\MC[+,2]}, if placed in the first column, occupies the entire row and is two rows tall.\\ +\qcmd{\MC[+,2]}, if placed in the second column, occupies the second column to the end of the table and is two rows tall.\\ In any of these examples, you can place the alignment letters anywhere. +So, \qcmd{\MC[l1,2b]} and \qcmd{\MC[1,2 lb]} are both left-bottom aligned (spaces are ignored). \llcmd{(override}% You may want to adjust the column specification of a multicolumn cell,\\ \llcmd{multicolumn)}for example, using -\texttt{@\{\}c@\{\}} to remove padding between the cell. +\texttt{(@\{\}c@\{\})} to remove padding between the cell. + \llcmd{}% You can place formatting like \cmd{\bfseries} here. -Here's an example. + +\subsection{Defaults}\label{s.def} +The \cmd{tabular[*]} environment is re-defined to use Lua pattern matching +to parse the column specification of the table. This is done to determine how many columns there are, +and what the current column type is, even if specifications like \cmd{r@{.}l*{3}{r}} are used. +If you have defined a column that expands many, you should register it with +\cmd{\setMCrepl{?}{??}} where \cmd{?} is your column and \cmd{??} is what it expands to. +You can also specify default horizontal and vertical alignments (ie if alignment not passed to \cmd{\MC}) +for an arbitrary column by \cmd{\setMChordef{?}{l|r|c}} and\\ +\cmd{\setMChordef{?}{t|m|b}}, where \cmd{?} is the column. +To add a column that should be surrounded by brackets for \cmd{siunitx} purposes, do so with \cmd{\addMCsicol{?}}. +S is included by default. + + +\newpage + +\subsection{Examples} + +\let\nl\\ + + +\subsubsection{A good use for headers} +\begin{LTXexample} +\begin{tabular}{ l l l }\toprule +\MC[+m]<\itshape>{A Decent + Example}\\\midrule + & \MC[2m]{Heading} \\\cmidrule{2-} +\MC[b,-2]{Multi\\Line} & A & B \\\midrule +\end{tabular} +\end{LTXexample} + +\subsubsection{A small example} + + +\begin{LTXexample} +\begin{tabular}{ l l l }\midrule + A & \MC[mc2,2]{Lttrs} \\ + B & \\ + 1 & A & B \\ +\end{tabular} +\end{LTXexample} + + +\subsubsection{A small bad example} +Notice that the top-aligned p-column +doesn't play particularly well with the middle aligned \cmd{\MC} +\begin{LTXexample} +\begin{tabular}{ p{1cm} l }\toprule + hello\newline world + & \MC[mr]{11\\2} \\ +\end{tabular} +\end{LTXexample} + + +\subsubsection{If you insist on vertical lines} +\begin{LTXexample} +\begin{tabular}{|c|c|c|} \hline +1 & 2 & 3\\\hline +4 & \MC[2,2cm](@{}c@{}|)% + <\ttfamily>{5}\\\cline{1-1} + & \MC[2](r|){} \\\hline%hacky fix +6 & 7 & 8\\\hline +\end{tabular} +\end{LTXexample} + + +\subsubsection{A perhaps useful example} + +\begin{LTXexample} +\begin{tabularx}{\linewidth}{S[table-format=2.1,table-alignment=left]X} +% err & ... \\% ERROR, not wrap + \MC{Error,\%} & Comment \\% MC helps + 3.1 & \MC[,2]{multi-line\\comment}\\ + 10.1& \\ + \MC[2c]{... ...} \\ +\end{tabularx} +\end{LTXexample} + +\subsubsection{A messy example} \begin{LTXexample} \begin{tabular}{| c | c | c | c | c | c |}\toprule @@ -136,23 +242,39 @@ Here's an example. \end{LTXexample} + + + %%% https://tex.stackexchange.com/questions/287346/width-of-column-after-multicolumn-header %\textbackslash MC[]{ l l ^ +%\begin{tabular}{l l l e}\toprule +%aaaaa & bbb & ccc & eee & fff\\ +%\MC{aaaaa}\\ +%\MC{a}\\\midrule +%\MC{a\\bbbbb} & x\\\midrule +%\makecell[br]{a\\b} & x\\\midrule +%\MC[+]{--- ---}\\ +%\end{tabular} +%\end{LTXexample} +%% WHY ISNT THIS RIGHT? +\newpage + + \section{Some additional rules} This package also redefines the \texttt{booktabs} midrules.\\ \llcmd{\gmidrule}is a full gray midrule.\\ @@ -171,11 +293,23 @@ override it for a specific rule by placing \qcmd{r} or \qcmd{l} with the span sp Here's an example: \begin{LTXexample} -\begin{tabular}{c c c c c c}\toprule - 1 & 2 & 3 & 4 & 5 & 6\\ \cmidrule{+1} % rule on last column - 1 & 2 & 3 & 4 & 5 & 6\\ \cmidrules{1,3-+3,+} % rule on first col, third to third last col, and last col - 1 & 2 & 3 & 4 & 5 & 6\\ \cmidrules{1,3-+3rl,+} % same as above, but trim middle - 1 & 2 & 3 & 4 & 5 & 6\\ \cmidrules(l){1,r3-+3,+1}% trim left for all, but only trim right for middle rule +\begin{tabular}{c c c c c c} + 1 & 2 & 3 & 4 & 5 & 6\\ + \cmidrule{+1} % rule on last column + 1 & 2 & 3 & 4 & 5 & 6\\ + \cmidrules{1,3-+3,+} % rule on first col, third to third last col, and last col + 1 & 2 & 3 & 4 & 5 & 6\\ + \cmidrules{1,3-+3rl,+} % same as above, but trim middle + 1 & 2 & 3 & 4 & 5 & 6\\ + \cmidrules(l){1,r3-+3,+1}% trim left for all, but only trim right for middle rule + 1 & 2 & 3 & 4 & 5 & 6\\ + \gcmidrule{+1} % rule on last column + 1 & 2 & 3 & 4 & 5 & 6\\ + \gcmidrules{1,3-+3,+} % rule on first col, third to third last col, and last col + 1 & 2 & 3 & 4 & 5 & 6\\ + \gcmidrules{1,3-+3rl,+} % same as above, but trim middle + 1 & 2 & 3 & 4 & 5 & 6\\ + \gcmidrules(l){1,r3-+3,+1}% trim left for all, but only trim right for middle rule \end{tabular} \end{LTXexample} @@ -192,13 +326,15 @@ You can change the step size and what kind of midrule you prefer. \end{verbatim} -Usage: Insert midrulex at the end of each row using the column spec. +To use, insert \cmd{@{\midrulex}} at the end of each row using the tabular column spec. Before you want counting to begin, you should -apply resetmidruleX (also to avoid header rows). +apply \cmd{\resetmidruleX} to avoid header rows being counted. +Use \cmd{\noalign{\resetmiduleX}} if you need place a rule on the same line or in a cell. + \begin{LTXexample} -\def\midruleXstep{4} -\def\midruleXrule{\cmidrules{1,3-4}} +\def\midruleXstep{3} +\def\midruleXrule{\cmidrules{1,3-4r}} \begin{tabular}{rclc@{\midruleX}} % ^^^ inject midrule \toprule -- cgit v1.2.3