4

I'm working in a tabular environment. I am a writing a set of 20+ rows in the environment. At first, I was going to number each row (automatically). But then it occurred to me that I could just number every fifth row: 5, 10, 15, 20... and so forth.

What is the simplest way to do this?

Here is my source code:

\documentclass[letterpaper,12pt]{article}

\usepackage{array}
\newcounter{rowcount}
\setcounter{rowcount}{0}


\usepackage{polyglossia}
\usepackage{fontspec}


\setmainlanguage[variant=us]{english}
\setotherlanguage{hebrew}
\setotherlanguage[variant=ancient]{greek}

\newfontfamily\greekfont[Script=Greek, Scale=MatchUppercase, Ligatures=TeX]{SBL BibLit}
\newfontfamily\hebrewfont[Script=Hebrew,Contextuals=Alternate,Ligatures=Required]{SBL BibLit}

\begin{document}

\section*{Fragment I.1: Psalm 17:26b-(LXX)}

\begin{greek}
\begin{tabular}{@{\stepcounter{rowcount}\therowcount\hspace*{\tabcolsep}}ccccccr}

  & ουεμ                                & καί μ(ετ)α                        & πρὸς                            & καὶ μ(ετ)α    & καὶ μ(ετ)α\\
  & γαβρ                                & ἀ\d{ν}δρ\d{ὸ}\d{ς}           & ἀνδρ\d{ὸ}\d{ς}             & ἀνδρὸς        & ἀνδρὸς\\
  & θαμιμ                               & τ(\d{ε}\d{λ})ε\d{ι}ο\d{υ}  & ἀκ\d{έ}ραιον                 & ἀθώιου        & ἀμωμου\\
  & θεμα\d{μ}\d{μ}\d{α}\d{μ}  & τ(ελ)(\d{ε}\d{ι})ωθήσ\d{ι} & ἀκέραια \d{π}ρ\d{ά}ζεις  & ἀθώος ἔσηι  &  ἄμωμος (ἔσ)ηι\\
  & ουεμ                                & καὶ μ(ετ)α                        & πρὸς                            & καὶ μ(ετ)α    & μ(ετ)α & 27\\ %how do I make this last column bold? Current commands (textbf and bfseries) do not seem to work...
  & ναβαρ

\end{tabular}
\end{greek}

\end{document}

At the end of the day, I could always just manually input on a separate column \therowcount. I guess I'm just being curious.

4

Nice question! Unfortunately my editor is struggling with the Greek characters, so I hope you do not mind me using ASCII characters in the example. Of course, the code does work in your use case, too. You can use \numexpr to define a mod function by exploiting that it rounds fractions.

\documentclass[letterpaper,12pt]{article}

\usepackage{array}
\newcounter{rowcount}
\setcounter{rowcount}{0}

\begin{document}
\begin{tabular}{@{\stepcounter{rowcount}%
\ifnum\the\numexpr\value{rowcount}-5*(\value{rowcount}/5)=0\relax
\number\value{rowcount}%
\fi
\hspace*{\tabcolsep}
}lc}
 & A \\
 & B \\
 & C \\
 & D \\
 & E \\
 & F \\
 & G \\
 & H \\
 & I \\
 & J \\
 & K \\
 & L \\
 & M \\
 & N \\
 & O \\
 & P \\
 & Q \\
 & R \\
 & S \\
 & T \\
 & U \\
 & V \\
 & W \\
 & X \\
 & Y \\
 & Z \\
\end{tabular}
\end{document}

enter image description here

One can of course use a macro and condense it but I wanted to keep the trick explicit. It is also obvious (I hope;-) how to generalize this to other integers, i.e. not 5. You can define this to be a new column type.

\documentclass[letterpaper,12pt]{article}
\usepackage{array}
\newcounter{rowcount}
\setcounter{rowcount}{0}
\newcolumntype{N}[1]{@{\stepcounter{rowcount}%
\ifnum\the\numexpr\value{rowcount}-#1*(\value{rowcount}/#1)=0\relax
\number\value{rowcount}%
\fi
\hspace*{\tabcolsep}
}l}
\begin{document}
\begin{tabular}{N{4}c}
 & A \\
 & B \\
 & C \\
 & D \\
 & E \\
 & F \\
 & G \\
 & H \\
 & I \\
 & J \\
 & K \\
 & L \\
 & M \\
 & N \\
 & O \\
 & P \\
 & Q \\
 & R \\
 & S \\
 & T \\
 & U \\
 & V \\
 & W \\
 & X \\
 & Y \\
 & Z \\
\end{tabular}
\end{document}
11
  • Thank you! This does the trick. I suppose the % signs are important. When I first input the code I ignored the percent signs and the output was off. Thank you for making the trick explicit, as I'm still pretty fresh to this world of LaTeX and I want to learn it well. – Rob28 Mar 10 '20 at 16:56
  • @Rob28 Yes, they are. They suppress spurious spaces, which can distort the output or have even more severe side-effects. – user194703 Mar 10 '20 at 16:57
  • 1
    @manooooh Sure, you can. The point is that this works without any packages, just using \numexpr. So this answer is simple, fast, easy to modify and understand, and does not suffer from incompatibilities or other threats. – user194703 Mar 10 '20 at 21:39
  • 1
    @Rob28 Sure. If rowcount is divisible by 5, \ifnum\the\numexpr\value{rowcount}-5*(\value{rowcount}/5) yields 0. What happens if rowcount is not divisible by 5? We need to know that \the\numexpr rounds the result. So 5*(\value{rowcount}/5) yields 0,0,5,5,5 for rowcount=1,2,3,4,5, and thus the whole term yields 0 only if rowcount is divisible by 5. – user194703 Apr 12 '20 at 14:52
  • 1
    The star * is just a multiplication sign. And 7 gets mapped to 7-5*round(7/5)=7-5*1=2. You can play with \documentclass{article} \newcounter{rowcount} \begin{document} \loop \stepcounter{rowcount}% \number\value{rowcount}:\the\numexpr\value{rowcount}-5*(\value{rowcount}/5)\relax :\the\numexpr5*(\value{rowcount}/5)\relax\par \ifnum\value{rowcount}<30 \repeat \end{document} or similar codes to see things more explicitly. – user194703 Apr 12 '20 at 17:13
2

Your idea is good. I defined a \countrows command that has as optional argument the interval of the numbering. Omitting it will number all lines.

I decided to set the numbers in the margin, with smaller type size, but this can be modified by changing the definition.

\documentclass[letterpaper,12pt]{article}
\usepackage{polyglossia}
\usepackage{fontspec}
\usepackage{array}

\setmainfont{Libertinus Serif}
\setmainlanguage[variant=us]{english}
\setotherlanguage[variant=ancient]{greek}

\ExplSyntaxOn
\int_new:N \g_robxxviii_rowcount_int

\NewDocumentCommand{\countrows}{O{1}}
 {
  \int_gincr:N \g_robxxviii_rowcount_int
  \int_compare:nT { \int_mod:nn { \g_robxxviii_rowcount_int } { #1 } = 0 }
   {
    \makebox[0pt][r]
     {
      \footnotesize
      \int_to_arabic:n { \g_robxxviii_rowcount_int }\hspace{\tabcolsep}
     }
   }
 }
\NewDocumentCommand{\resetcountrows}{}
 {
  \int_gzero:N \g_robxxviii_rowcount_int
 }
\ExplSyntaxOff

\begin{document}

\section*{Fragment I.1: Psalm 17:26b-(LXX)}

\begin{greek}
\noindent\resetcountrows
\begin{tabular}{
  @{\countrows[5]}
  ccccc
  >{\bfseries}r
  @{}
}
ουεμ     & καί μ(ετ)α     & πρὸς            & καὶ μ(ετ)α & καὶ μ(ετ)α\\
γαβρ     & ἀν̣δρὸ̣ς̣         & ἀνδρὸ̣ς̣          & ἀνδρὸς     & ἀνδρὸς\\
θαμιμ    & τ(ε̣λ̣)ει̣ου̣      & ἀκέ̣ραιον        & ἀθώιου     & ἀμωμου\\
θεμαμ̣μ̣α̣μ̣ & τ(ελ)(ε̣ι̣)ωθήσι̣ & ἀκέραια π̣ρά̣ζεις & ἀθώος ἔσηι &  ἄμωμος (ἔσ)ηι\\
ουεμ     & καὶ μ(ετ)α     & πρὸς            & καὶ μ(ετ)α & μ(ετ)α & 27\\ 
ναβαρ \\
ουεμ     & καί μ(ετ)α     & πρὸς            & καὶ μ(ετ)α & καὶ μ(ετ)α\\
γαβρ     & ἀν̣δρὸ̣ς̣         & ἀνδρὸ̣ς̣          & ἀνδρὸς     & ἀνδρὸς\\
θαμιμ    & τ(ε̣λ̣)ει̣ου̣      & ἀκέ̣ραιον        & ἀθώιου     & ἀμωμου\\
θεμαμ̣μ̣α̣μ̣ & τ(ελ)(ε̣ι̣)ωθήσι̣ & ἀκέραια π̣ρά̣ζεις & ἀθώος ἔσηι &  ἄμωμος (ἔσ)ηι\\
ουεμ     & καὶ μ(ετ)α     & πρὸς            & καὶ μ(ετ)α & μ(ετ)α & 27\\ 
ναβαρ \\
ουεμ     & καί μ(ετ)α     & πρὸς            & καὶ μ(ετ)α & καὶ μ(ετ)α\\
γαβρ     & ἀν̣δρὸ̣ς̣         & ἀνδρὸ̣ς̣          & ἀνδρὸς     & ἀνδρὸς\\
θαμιμ    & τ(ε̣λ̣)ει̣ου̣      & ἀκέ̣ραιον        & ἀθώιου     & ἀμωμου\\
θεμαμ̣μ̣α̣μ̣ & τ(ελ)(ε̣ι̣)ωθήσι̣ & ἀκέραια π̣ρά̣ζεις & ἀθώος ἔσηι &  ἄμωμος (ἔσ)ηι\\
ουεμ     & καὶ μ(ετ)α     & πρὸς            & καὶ μ(ετ)α & μ(ετ)α & 27\\ 
ναβαρ \\
ουεμ     & καί μ(ετ)α     & πρὸς            & καὶ μ(ετ)α & καὶ μ(ετ)α\\
γαβρ     & ἀν̣δρὸ̣ς̣         & ἀνδρὸ̣ς̣          & ἀνδρὸς     & ἀνδρὸς\\
θαμιμ    & τ(ε̣λ̣)ει̣ου̣      & ἀκέ̣ραιον        & ἀθώιου     & ἀμωμου\\
θεμαμ̣μ̣α̣μ̣ & τ(ελ)(ε̣ι̣)ωθήσι̣ & ἀκέραια π̣ρά̣ζεις & ἀθώος ἔσηι &  ἄμωμος (ἔσ)ηι\\
ουεμ     & καὶ μ(ετ)α     & πρὸς            & καὶ μ(ετ)α & μ(ετ)α & 27\\ 
ναβαρ \\
\end{tabular}
\end{greek}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.