Total number of points

As long as you are just dealing with integer points, you can use a counter to sum them up. As you want to include the sum before they are actually added, the package totcount comes in handy:

\documentclass{article}

\usepackage{totcount}
\newtotcounter{totalpoints}
\setcounter{totalpoints}{0}

\begin{document}

Total points are \the\numexpr\totvalue{totalpoints}

\begin{enumerate}

\item [5 points]\addtocounter{totalpoints}{5} Here is the first question.

\item [6 points]\addtocounter{totalpoints}{6} Here is the second.

\end{enumerate}


\end{document}

enter image description here


There are several packages and classes that deal with making exams and the like (see https://www.ctan.org/topic/exam). One such package is exsheets, which does something like what you're after, although it is a bit more fancy. You can easily add bonus points as well. Note that two compilations are needed for the total points to be printed, just as with cross references.

Note that exsheets has a lot more features than the very simple example below. You can for examples write up solutions, and print them where they're written, or gathered somewhere else in the document, or not at all. And there are a lot of ways of customizing things. Have a look at the manual, and also questions here on the site.

\documentclass{article}
\usepackage{exsheets}
\SetupExSheets[question]{type=exam}
\begin{document}
Total points are: \totalpoints 
\begin{question}{5+3} % 5 points and 3 bonus points
...
\end{question}

\begin{question}{15}
...
\end{question}

\begin{question}{3}
...
\end{question}
\end{document}

enter image description here


A little bit more fancy than requested by the O.P. (Sam Carter's or Torbjorn's solutions are good as well):

I changed the syntax of \item a little bit, by adding the 2nd optional argument <X> where X is a placeholder for the credit points for this task. Omitting <X> means 0 credits and is neither added nor shown.

\documentclass{article}
\usepackage{totcount}
\usepackage{marginnote}
\usepackage{xparse}

\makeatletter
\let\latex@@item\item

\RenewDocumentCommand{\item}{od<>}{%
  \IfValueTF{#1}{%
    \latex@@item[#1]
  }{%
    \latex@@item%
  }%
  \IfValueT{#2}{%
    \marginnote{\bfseries \raggedleft #2 P.}
    \addtocounter{totalcredits}{#2}%
  }%
}
\makeatother
\newtotcounter{totalcredits}

\begin{document}
There are \total{totalcredits} credits to gain here!

\begin{enumerate}
  \item<17> Foo
  \item<4>  Bar
  \item<1000> More foobar
  \item[A)]<-3> Even more foobar
\end{enumerate}


\end{document}

enter image description here

Tags:

Calculations