6

I have been given the task of creating a LaTeX template for producing marking reports for student research proposals. We need an easy way to assign marks (numeric values) to particular qualities of the proposal, such as the lit. review, and to have sections for comments. Everything must be exceptionally easy to use for LaTeX beginners. And for some reason, a sliding bar representing each allocated mark must be included.

The difficulty I am having is in creating a variable that holds a marks. These mark must be 1) summed for a final mark and 2) used for the visual slider bar.

I have tried counter (as seen in my MWE), but the counter uses whole numbers and the slider expects floating point numbers. In addition, the slider needs to show the relative mark, and some of the qualities may count for 5%, some for 10%, etc, thus some calculation will have to be performed in LaTeX.

In summary, how do I hold a numeric value that can satisfy these requirements? 1) allow for summing 2) allow for calculations and use in another macro.

I have tried to express this question in the spirit of StackExchange. Please forgive me if I have erred; my intention is not to waste your time.

    \documentclass[a4paper]{paper}   
    \usepackage{graphicx}
    \usepackage{xcolor}
    \usepackage{calc}
    \usepackage{tikz}
    \usetikzlibrary{calc,shadows,shadows.blur}

    \def\IosSevenSlider#1#2{
        \tikz[baseline=-0.1cm]{
            \coordinate (start) at (0,0);
            \coordinate (end) at (#1,0);
            \coordinate (mark) at ($(start)!#2!(end)$);
            \useasboundingbox (start|- 0,-.25) rectangle (end|- 0, .25);
            \draw[line width=0.4mm, line cap=round, blue!50!cyan] 
                 (start) -- (mark) edge[lightgray] (end);
            \node[fill=white, draw=lightgray, very thin,
                blur shadow={shadow xshift=0pt, shadow opacity=20, shadow yshift=-0.9mm,
                             shadow blur steps=6, shadow blur radius=0.3mm},
                circle, minimum size=0.25cm, inner sep=0pt] at (mark) {};
        }
    }


    % SETS UPS MARK VARIABLES, Q1 = Question 1 etc)
    \newcounter{q1} % Counts for 10%
    \newcounter{q2} % Counts for  5%

% THIS IS WHERE YOU WILL ENTER YOUR MARKS PER QUESTION
\setcounter{q1}{5}
\setcounter{q2}{3}

\begin{document} 
\begin{table}
    \centering
        \begin{tabular}{ll}

% Using the value for q1 results in the slider overshooting!        
Overall Presentation (Structure and English)    & \setlength{\fboxsep}{0pt} \fbox{\IosSevenSlider{5cm}{\value{q1}}} \\
% A hardcoded value works just fine. 
Clarity of title (Accurate and concise) & \setlength{\fboxsep}{0pt} \fbox{\IosSevenSlider{5cm}{.5}} \\
        \end{tabular}

\end{table}
\end {document}
  • 1
    see for example tex.stackexchange.com/questions/104446/… – David Carlisle Jul 18 '14 at 19:36
  • 1
    When I did something like this (for some insane reason), I used fp for setting numbers and calculations. I used a modified form of a class gradelist which was part of a class package. However, searching on ctan for 'class' produces rather too many hits... and I don't even know if that's where I got the original. (This didn't involve sliders but it did automate the calculation of marks etc.) – cfr Jul 18 '14 at 21:54
5

There is no problem in using ordinary latex counters to keep track of the total. Just use \addtocounter to add up marks and then print the total at the end.

With your sliders there are two issues:

  • First, tikz expects numerical coordinates yet your macro asks it to make (5cm,0) into a coordinate: just use (5,0).
  • Secondly, you are trying to position the slider using (start)!#2!(end) so #2 must be between 0 and 1 yet you are giving it the full mark. You need 5/10, say, rather than 5. This is why you had the overflow.
  • I suspect that you probably don't want the width of the slider as a parameter of \IosSevenSlider and, instead, that you want the maximum mark for the question to be the parameter.

Finally, as you want to make this template easy for non-LaTeX users to use I suggest that you put the meat of your macros into a separate class file and then simply call an environment to create your table. Hacking your code, here's my suggestion for the class file:

\LoadClass[a4paper]{paper}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{calc,shadows,shadows.blur}

\setlength{\fboxsep}{0pt}
% IsoSevenSlider[slider length]{mark}{maximum mark}
\newcommand\IosSevenSlider[3][4]{\fbox{%
    \tikz[baseline=-0.1cm]{
        \coordinate (start) at (0,0);
        \coordinate (end) at (#1,0);
        \coordinate (mark) at ($ (start)! {#2/#3} !(end) $);
        \useasboundingbox (start|- 0,-.25) rectangle (end|- 0, .25);
        \draw[line width=0.4mm, line cap=round, blue!50!cyan]
             (start) -- (mark) edge[lightgray] (end);
        \node[fill=white, draw=lightgray, very thin,
            blur shadow={shadow xshift=0pt, shadow opacity=20, shadow yshift=-0.9mm,
                         shadow blur steps=6, shadow blur radius=0.3mm},
            circle, minimum size=0.25cm, inner sep=0pt] at (mark) {};
    }}}

% Counters to keep track of students' marks and the maximum possible mark
\newcounter{TotalMarks}
\newcounter{MaximumMarks}

% \Mark{mark} or \Mark[maximum (default=5)]{mark}
\newcommand\Mark[2][5]{#2&\IosSevenSlider{#2}{#1}%
  \addtocounter{TotalMarks}{#2}\addtocounter{MaximumMarks}{#1}}

\newenvironment{Marks}%
  {\document\center\tabular{lll}}%
  {\textbf{Total marks} & \theTotalMarks &\IosSevenSlider{\theTotalMarks}{\theMaximumMarks}\\%
  \endtabular\endcenter\enddocument}

\endinput

If this is called marks.cls then your template file would look like this:

\documentclass{marks}

\begin{Marks}
% Using the value for q1 results in the slider overshooting!
Overall Presentation (Structure and English)    & \Mark{5}\\
% A hardcoded value works just fine.
Clarity of title (Accurate and concise) & \Mark{3} \\
\end{Marks}

This produces:

enter image description here

In doing this I have taken a few liberties with your macros.

  • The \IsoSevenSlider now takes three arguments: #1=width of slider (optional), #2=mark and #3=maximum possible mark. Probably #1 can be dropped. I have just hacked your tikz code to make it work; in particular, I didn't try to improve or modify it:) This macro is not called directly in the template. By default #1=4 - this value was chosen only to make the slider fit within the page margins.
  • The Marks environment both begins and closes the document and draws the table. It finishes by adding a line for the total mark, together with slider.
  • The \Mark macro prints the students' mark and adds it to the running total. The macro has optional argument that specifies the maximum mark for the question (this defaults to 5). Note that the tabular environment created by the Marks environment now has three columns and that \Mark creates entries in the last two.

Note that I haven't defined counters for the individual question marks. Instead, \Mark prints the the mark and adds it to the running total (and it keeps track of the maximum possible mark). Unless you want to use the individual marks later you don't need to remember them (if you do need these marks later then it is not difficult to modify \Mark so that it will remember them as well).

Edit It occurs to me that you can simplify the LaTeX for your novice users even further by moving the & and \\ into the \Mark macro by changing its definition to:

\newcommand\Mark[2][5]{&#2&\IosSevenSlider{#2}{#1}\\%
  \addtocounter{TotalMarks}{#2}\addtocounter{MaximumMarks}{#1}}

With this change your template file becomes:

\documentclass{marks}

\begin{Marks}
Overall Presentation (Structure and English) \Mark{5}
Clarity of title (Accurate and concise) \Mark{3}
\end{Marks}
  • 1
    You have solved my problem, and problems I didn't know I had, and helped improve my understanding of LaTeX. Thank you. – Evyn Jul 19 '14 at 16:06

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.