我正在尝试向表格中添加自动行号和点填充,并使用一个切换按钮禁用某些行的自动行号和点填充,但效果不如预期。在下面的 MWE 中,切换按钮适用于行号,但不能用于填充。我该如何修复这个问题?
换句话说,为什么切换按钮似乎过早地恢复为真?
梅威瑟:
\documentclass{memoir}
\usepackage{etoolbox}
\AtBeginEnvironment{tabularx}{%
\ifcscounter{c@rownumbers}{}{\newcounter{rownumbers}}%
\setcounter{rownumbers}{0}%
\providetoggle{showrownumber}%
\toggletrue{showrownumber}%
\newcommand\ifshowrownumber[1]{%
\iftoggle{showrownumber}{#1}{}%
}
\newcommand\nonum{%
\togglefalse{showrownumber}%
}
\newcommand\rownumberdisplay{%
\makebox[1.5em][r]{\ifshowrownumber{%
\stepcounter{rownumbers}\arabic{rownumbers}.%
}}\space%
}
\newcommand\rowfill{%
\ifshowrownumber{\dotfill}%
}
\newcommand\resetrownumber{%
\setcounter{rownumbers}{0}%
}
\newcommand\rowdone{%
\toggletrue{showrownumber}%
}
}
\begin{document}
\begin{tabularx}{.9\textwidth}{r<{\rownumberdisplay} @{} X<{\rowfill} @{} r r<{\rowdone}}%
\toprule%
\nonum & Name & A & B\\
\midrule%
\nonum & \emph{Section} \\
& Name & 100.0 & 3.5 \\
\nonum & -- and Name & 10.15 & 56.8 \\
\nonum & \emph{Section} \\
& Name & 66.4 & 43.1 \\
& Name & 66.4 & 43.1 \\
& Name & 66.4 & 43.1 \\
& Name & 66.4 & 43.1 \\
& Name & 66.4 & 43.1 \\
& Name & 66.4 & 43.1 \\
& Name & 66.4 & 43.1 \\
& Name & 66.4 & 43.1 \\
\bottomrule%
\end{tabularx}
\end{document}
答案1
像这样?
它不是自动的。当您手动中断行编号时,您可以对 执行相同的操作\dotfill
:
\documentclass{memoir}
\newcounter{rownum}
\newcommand{\getEqNo}{\refstepcounter{rownum}
\therownum.\,}
\newcommand\mcl[1]{\multicolumn{1}{l}{#1}}
\begin{document}
\begin{tabularx}{.9\textwidth}{>{\getEqNo}r @{} X<{\dotfill} @{} r r}
\toprule
\mcl{} & \mcl{Name} & A & B \\
\midrule
\mcl{} & \mcl{\emph{Section}} & & \\
& Name & 100.0 & 3.5 \\
\mcl{} & \mcl{-- and Name} & 10.15 & 56.8 \\
\mcl{} & \mcl{\emph{Section}} & & \\
& Name & 66.4 & 43.1 \\
& Name & 66.4 & 43.1 \\
& Name & 66.4 & 43.1 \\
& Name & 66.4 & 43.1 \\
& Name & 66.4 & 43.1 \\
& Name & 66.4 & 43.1 \\
& Name & 66.4 & 43.1 \\
& Name & 66.4 & 43.1 \\
\bottomrule
\end{tabularx}
\end{document}