I am writing a command \newrow to generate one row in a longtable. The problem is that the tabular environment here can not see the value of \subColWid (output is 0pt). This occurs only when multirow is also used. Can anyone help me to figure out why the updated \subColWid by \setlength is invisible in the tabular (including column specification). Thanks.
\documentclass{article}
\usepackage{fullpage}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow}
% define my macros
\newlength{\firstColWid}
\newlength{\secondColWid}
\newlength{\subColWid}
\setlength\firstColWid{0.1\textwidth}
\setlength\secondColWid{0.9\textwidth}
%\setlength{\subColWid}{0.5\secondColWid} % uncomment this line to see correct result
\setlength{\tabcolsep}{0pt}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\newcommand{\newrow}[2]{ % a command to produce a row spanning two lines
% set width for each cell in the second column
\setlength\subColWid{0.2\secondColWid} % this has effect here but not in the
%tabular
% \the\subColWid
\multirow{2}{*}{#1} & subColWid = \the\subColWid \\ \cline{2-2}
&
% use a tabular to represent all the remaining values
\begin{tabular}[c]{ @{\extracolsep{\fill}} *{2}{M{\subColWid} | }}
% subColWid = \the\subColWid & #2 \\
#2 & \the\subColWid \\
\end{tabular}
}
\begin{document}
\begin{longtable}[c]{|M{\firstColWid}|@{\extracolsep{\fill}} M{\secondColWid}|} %
\hline
% give row number and another cell
\newrow{1}{Row1} \\ \hline
\newrow{2}{Row2} \\
\hline
\end{longtable}
\end{document}
TeXgroup and as such, lengths settings hold only within a group, not outside, i.e. they will not survive the change from one cell to the next one – Nov 05 '14 at 04:48\subColWidis assigned a value which is realized when it's expanded. LaTeX (and TeX) have only two levels: global and local. By which I mean, if it's not local, then it's global. Here a longish explanation. – A.Ellett Nov 05 '14 at 05:40