admin管理员组文章数量:1313807
How come that this piece of code does not compile right in Texmaker on an iMac?
\documentclass{article}
\usepackage{tabularray}
\newcounter{linecounter}
\begin{document}
% Initialize the line counter
\setcounter{linecounter}{1}
\begin{tblr}{
colspec={@{}ll@{}}}
\hline
\textbf{Line Number} & \textbf{Text} \\
\hline
\thelinecounter & First line of text. \\
\addtocounter{linecounter}{1}
\thelinecounter & Second line of text. \\
\addtocounter{linecounter}{1}
\thelinecounter & Third line of text. \\
%\addtocounter{linecounter}{1}
\hline
\end{tblr}
\end{document}
gives
Line Number Text
5 First line of text.
7 Second line of text.
9 Third line of text.
How come that this piece of code does not compile right in Texmaker on an iMac?
\documentclass{article}
\usepackage{tabularray}
\newcounter{linecounter}
\begin{document}
% Initialize the line counter
\setcounter{linecounter}{1}
\begin{tblr}{
colspec={@{}ll@{}}}
\hline
\textbf{Line Number} & \textbf{Text} \\
\hline
\thelinecounter & First line of text. \\
\addtocounter{linecounter}{1}
\thelinecounter & Second line of text. \\
\addtocounter{linecounter}{1}
\thelinecounter & Third line of text. \\
%\addtocounter{linecounter}{1}
\hline
\end{tblr}
\end{document}
gives
Line Number Text
5 First line of text.
7 Second line of text.
9 Third line of text.
Share
Improve this question
edited Jan 31 at 22:02
Robert
8,69354 gold badges129 silver badges170 bronze badges
asked Jan 31 at 14:31
algonalgon
111 bronze badge
1 Answer
Reset to default 0tabularray
processes the content of a table multiple times to determine the widths of columns etc.
You can use the counter
library to get the correct numbering:
\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{counter}
\newcounter{linecounter}
\begin{document}
% Initialize the line counter
\setcounter{linecounter}{1}
\begin{tblr}{
colspec={@{}ll@{}}}
\hline
\textbf{Line Number} & \textbf{Text} \\
\hline
\thelinecounter & First line of text. \\
\addtocounter{linecounter}{1}\thelinecounter & Second line of text. \\
\addtocounter{linecounter}{1}\thelinecounter & Third line of text. \\
%\addtocounter{linecounter}{1}
\hline
\end{tblr}
\end{document}
Or you could use the existing counters tabularray
already provides:
\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{counter}
\newcounter{linecounter}
\begin{document}
\begin{tblr}{
colspec={@{}ll@{}},
}
\hline
\textbf{Line Number} & \textbf{Text} \\
\hline
\the\numexpr\arabic{rownum}-1 & First line of text. \\
\the\numexpr\arabic{rownum}-1 & Second line of text. \\
\the\numexpr\arabic{rownum}-1 & Third line of text. \\
\hline
\end{tblr}
\end{document}
本文标签: latexgenerating count inside tabularray environmentStack Overflow
版权声明:本文标题:latex - generating count inside tabularray environment - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741913711a2404596.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论