Text Formatting ⇒ Print total number of \item entries in an enumerate list
- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
Print total number of \item entries in an enumerate list
Problem:
I would like LaTeX to print the total number of \item entries in my list.
In my attached example the number I would like LaTeX to print is 6, but there are over 500 entries in my ``real'' list.
P.S. I'm new at LaTeX...
- Attachments
-
- list.tex
- Part of my enumerate list.
- (987 Bytes) Downloaded 340 times
-- Zapp Brannigan, Futurama (season 1, episode 4)
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Print total number of \item entries in an enumerate list
Best regards and welcome to the board
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
Re: Print total number of \item entries in an enumerate list
I don't know exactly what to write in my document---can you please help me? I'm probably just ``dumb'' but I can't figure out what the problem is.
See the attached file for my poor attempt. LaTeX doesn't print anything when I try this.
- Attachments
-
- list.tex
- (999 Bytes) Downloaded 355 times
-- Zapp Brannigan, Futurama (season 1, episode 4)
- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
Re: Print total number of \item entries in an enumerate list
I have attached the updated (La)TeX file together with the log file.
I hope you can and will help me.
-- Zapp Brannigan, Futurama (season 1, episode 4)
- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
Re: Print total number of \item entries in an enumerate list
I have attached my TeX file so other people who are interested can see a possible solution.
- Attachments
-
- list.tex
- (1.03 KiB) Downloaded 368 times
-- Zapp Brannigan, Futurama (season 1, episode 4)
Print total number of \item entries in an enumerate list
you can create a new counter and use it to keep record of the total number of times that the \movie command was used, as the following code illustrates:
Code: Select all
\documentclass[a4paper,12pt]{article}
\usepackage{enumerate}
\usepackage{color}
\usepackage{mathtools}
\usepackage[colorlinks=true,urlcolor=black]{hyperref}
\newcounter{mycounter}
\newcommand{\options}[3]{\color{#1}#2\fontsize{#3}{#3}\selectfont}
\newcommand{\movie}[4]{\stepcounter{mycounter}%
\item \fontsize{12pt}{12pt}\selectfont
\textsf{[#4]\enskip\href{#1}{#2} (#3)}
}
\begin{document}
\begin{enumerate}[\options{blue}{\bfseries\sffamily}{10pt}$\star$\qquad]
\movie{http://www.imdb.com/title/tt0020629/}{All Quiet on the Western Front}{1930}{8,1}
\movie{http://www.imdb.com/title/tt0074119/}{All the President's Men}{1976}{8,0}
\movie{http://www.imdb.com/title/tt0765429/}{American Gangster}{2007}{8,0}
\movie{http://www.imdb.com/title/tt0120586/}{American History X}{1998}{8,6}
\movie{http://www.imdb.com/title/tt0052561/}{Anatomy of a Murder}{1959}{8,1}
\movie{http://www.imdb.com/title/tt0078788/}{Apocalypse Now}{1979}{8,6}
\end{enumerate}
My total number of movies is \themycounter.
\setcounter{mycounter}{0} % to reinitialize the counter, if necessary
\end{document}