As hpesoj626 said in a comment, textpos
and tikz
are classical approaches to put a picture at an absolute position inside a page (i.e: at top right, or at (-1cm,-1cm) being the top right corner of the page the origin, and so on).
But in this case I want to suggest a different and a bit "hackish" approach. Instead of putting the logo at an absolute position, your sample image suggest that it could be put also relative to the School Name (say for example, 3cm at the right and 1cm below of the school name). In this case no additional packages are required, standard LaTeX picture environment can do it. The trick is to define a picture of zero size so that it does not affect the centering of the titles. This is a MWE document which shows how.
\documentclass{article}
\usepackage{graphicx}
\def\LOGO{%
\begin{picture}(0,0)\unitlength=1cm
\put (3,-1) {\includegraphics[width=5em]{star.mps}}
\end{picture}
}
\begin{document}
\begin{center}
\sffamily\bfseries
{\Large School Name}\LOGO\\
College Name\\
Department Name\\
First Semester SY 2012-2013
\end{center}
\hrulefill\par
Etc...
\end{document}
Results in:
As you want to put the scores for the question parts in two columns, and as the number of scores is variable, you will need to store the scores somewhere and then generate the whole table at the end. Building on my previous idea, I would put the scores into a LaTeX3 sequence, whilst keeping track of the total score and the number of scores as you go. As in my other post, I would then define a \GradeBook
command to produce your custom table:
I am not sure how "multiple choice" and "free response" questions are coded when using the exam class, which is why I asked for a minimal working example :), so in the code below I have cheated and hard-code these marks using:
\def\multiplechoice{54}
\def\freeresponse{46}
Apart from this, everything is automatic. Here is the full code:
\documentclass[addpoints]{exam}
\usepackage[table]{xcolor}
\usepackage{xparse,xpatch}
% redefine \part command to be \mypart
\appto\parts{\let\exampart\part\let\part\mypart}
\def\multiplechoice{54}
\def\freeresponse{46}
\makeatletter
\ExplSyntaxOn
% this will become a sequence of the part numbers and scores
% like: 1a&10&, 1b&8&, 1c&9&, 2a&6, 2b&8&, 3&12&, 4&14&, ...
\seq_new:N \g_part_scores_seq
\tl_new:N \g_grade_table_tl
\int_new:N \g_total_score_int% this will be the exam score
\int_new:N \g_number_of_scores_int
\NewDocumentCommand\mypart{o}{
\IfNoValueTF{#1}{\exampart}{
% don't do anything special inside solutions
\if@insolution\exampart[#1]
\else\exampart[#1]
% store both the part number and score in \g_part_scores_seq
% together with their column separators for the tabular env
\tl_set:Nx \l_tmpa_tl { \arabic{question}\alph{partno} }
\tl_put_right:Nn \l_tmpa_tl {&}
\tl_put_right:No \l_tmpa_tl {#1}
\tl_put_right:Nn \l_tmpa_tl {&}
\seq_gput_right:No \g_part_scores_seq \l_tmpa_tl
% increment the running total and number of scores
\int_gadd:Nn \g_total_score_int {#1}
\int_gincr:N \g_number_of_scores_int
\fi
}
}
% print row #1 of the part scores in the grade table
\cs_new:Nn \__add_row_to_grade_table:n {
\tl_gput_right:Nx \g_grade_table_tl {\seq_item:Nn \g_part_scores_seq {#1}}
\tl_gput_right:Nn \g_grade_table_tl { & }
\tl_gput_right:Nx \g_grade_table_tl {\seq_item:Nn \g_part_scores_seq {#1+\g_number_of_scores_int/2}}
\tl_gput_right:Nn \g_grade_table_tl {\\\hline}
}
\NewDocumentCommand\GradeTable{}{% the new grade table
% we need an exam number of scores so add two
% empty cells if we have an odd number
\int_if_odd:nT {\g_number_of_scores_int} {
\seq_gput_right:Nn \g_part_scores_seq {&}
\int_ginc:N \g_number_of_scores_int
}
\int_gset:Nn \g_number_of_scores_int {\g_number_of_scores_int}
\int_gadd:Nn \g_total_score_int { \multiplechoice }
\int_gadd:Nn \g_total_score_int { \freeresponse }
% create the grade table
\tl_gclear:N \g_grade_table_tl
\int_step_function:nnN {1} {\g_number_of_scores_int/2} \__add_row_to_grade_table:n
\begin{tabular}{|c|c|c|c|c|c|}\hline\rowcolor{gray!20}
Question & Points~Possible & Points~Earned & Question & Points~Possible & Points~Earned \\\hline
\tl_use:N \g_grade_table_tl
\multicolumn2{c|}{}&\multicolumn{2}{r|}{Multiple~Choice}
& \multiplechoice & \\\cline{3-6}
\multicolumn2{c|}{}&\multicolumn{2}{r|}{Free~response}
& \freeresponse & \\\cline{3-6}
\multicolumn2{c|}{}&\multicolumn{2}{r|}{\textit{Exam~total}}
& \int_use:N \g_total_score_int & \\\cline{3-6}
\end{tabular}
}
\ExplSyntaxOff
\makeatother
\begin{document}
\begin{questions}
\question
What if there were no air?
\begin{parts}
\part[4]
Describe the effect on the balloon industry.
\part[6]
Describe the effect on the aircraft industry.
\end{parts}
\question
\begin{parts}
\part[12]
Define the universe.
Give three examples.
\part[8]
If the universe were to end, how would you know?
\end{parts}
\end{questions}
\GradeTable
\end{document}
EDIT
Here is updated (and streamlined) version of the code above that saves the data to the aux file and reads it back in to construct the grade table. This allows you to put the table anywhere you like, including at the start of the document but also means that you will have to LaTeX the file twice before you see any scores.
After compiling the document two or more times, the updated MWE gives the following output:
This is much the same as before except that the table is now at the top of the document. If you compile the document only once then the grades table will have no scores for individuals questions, or their parts, and the total will be 0. Here is the updated code:
\documentclass[addpoints]{exam}
\usepackage[table]{xcolor}
\usepackage{xparse,xpatch,etoolbox}
% redefine \question command to be \myquest
\appto\questions{\let\examquestion\question\let\question\myquestion}
% redefine \part command to be \mypart
\appto\parts{\let\exampart\part\let\part\mypart}
\def\multiplechoice{5}
\def\freeresponse{6}
\makeatletter
\ExplSyntaxOn
% this will become a sequence of the part numbers and scores
% like: 1a,10,1b,8,1c,9,2a,6,2b,8,3,12,4,14, ...
\clist_new:N \g_grades_clist
\clist_new:N \g_grades_aux_clist
\int_new:N \g_row_int
\int_new:N \g_multiple_choice_int
\int_new:N \g_free_response_int
\int_new:N \g_grade_total_int
\int_new:N \g_number_of_scores_int
% add a question/part number and score to \g_grades_clist
\cs_new:Nn \__add_to_grades_list:nn {
\clist_gput_right:Nx \g_grades_clist { #1 }
\clist_gput_right:Nx \g_grades_clist { #2 }
}
\NewDocumentCommand\myquestion{o}{
\IfNoValueTF{#1}{\examquestion}{
% don't do anything special inside solutions
\if@insolution\examquestion[#1]
\else\examquestion[#1]
% store both the part number and score in \g_grades_clist
\__add_to_grades_list:nn { \arabic{question} } { #1 }
\fi
}
}
\NewDocumentCommand\mypart{o}{
\IfNoValueTF{#1}{\exampart}{
% don't do anything special inside solutions
\if@insolution\exampnrt[#1]
\else\exampart[#1]
% store both the part number and score in \g_grades_clist
\__add_to_grades_list:nn { \arabic{question}\alph{partno} } { #1 }
\fi
}
}
\AtEndDocument{
\iow_now:cx { @auxout } {
\token_to_str:N \SetGradeList { \g_grades_clist } ^^J
\token_to_str:N \SetMultipleChoice {\multiplechoice} ^^J
\token_to_str:N \SetFreeResponse {\freeresponse} ^^J
}
}
% set grade list, multiple choice and free responses from the aux file
\NewDocumentCommand\SetGradeList{m}{\clist_gset:Nn \g_grades_aux_clist {#1}}
\NewDocumentCommand\SetMultipleChoice{m}{\int_gset:Nn \g_multiple_choice_int {#1}}
\NewDocumentCommand\SetFreeResponse{m}{\int_gset:Nn \g_free_response_int {#1}}
% print row #1 of the part scores in the grade table
\cs_new:Nn \__add_row_to_grade_table: {
\int_gincr:N \g_row_int
\clist_item:Nn \g_grades_aux_clist {2*\g_row_int-1}
&\clist_item:Nn \g_grades_aux_clist {2*\g_row_int}
\int_gadd:Nn \g_grade_total_int {\clist_item:Nn \g_grades_aux_clist {2*\g_row_int}}
&&
\int_compare:nTF {2*\g_row_int+\g_number_of_scores_int <= \clist_count:N \g_grades_aux_clist }{
\clist_item:Nn \g_grades_aux_clist {2*\g_row_int+\g_number_of_scores_int-1}
&\clist_item:Nn \g_grades_aux_clist {2*\g_row_int+\g_number_of_scores_int}
\int_gadd:Nn \g_grade_total_int {\clist_item:Nn \g_grades_aux_clist {2*\g_row_int+\g_number_of_scores_int}}
}{&}
&\\\hline
\int_compare:nT {\g_row_int < \g_number_of_scores_int/2} { \__add_row_to_grade_table: }
}
\NewDocumentCommand\PrintGradeTable{}{% the new grade table
% we need an exam number of scores so add two
% empty cells if we have an odd number
\int_set:Nn \g_number_of_scores_int {(\clist_count:N \g_grades_aux_clist)/2}
\int_if_odd:nT {\g_number_of_scores_int} {
\int_add:Nn \g_number_of_scores_int {1}
}
\int_gzero:N \g_row_int % a counter to step through the rows
\int_add:Nn \g_grade_total_int { \g_multiple_choice_int }
\int_add:Nn \g_grade_total_int { \g_free_response_int }
% create the grade table
\begin{tabular}{|c|c|c|c|c|c|}\hline\rowcolor{gray!20}
Question & Points~Possible & Points~Earned & Question & Points~Possible & Points~Earned \\\hline
% the number of rows that we need is \g_number_of_scores_int/2
\int_compare:nT {\g_number_of_scores_int>0} { \__add_row_to_grade_table: }
\multicolumn2{c|}{}&\multicolumn{2}{r|}{Multiple~Choice}
& \int_use:N \g_multiple_choice_int & \\\cline{3-6}
\multicolumn2{c|}{}&\multicolumn{2}{r|}{Free~response}
& \int_use:N \g_free_response_int & \\\cline{3-6}
\multicolumn2{c|}{}&\multicolumn{2}{r|}{\textit{Exam~total}}
& \int_use:N \g_grade_total_int & \\\cline{3-6}
\end{tabular}
}
\ExplSyntaxOff
\makeatother
\begin{document}
\PrintGradeTable
\begin{questions}
\question
\begin{parts}
\part[1]
\part[2]
\end{parts}
\question
\begin{parts}
\part[4]
\part[2]
\end{parts}
\question
\begin{parts}
\part[2]
\part[4]
\part[4]
\part[1]
\end{parts}
\question[5]
\end{questions}
\end{document}
The code is probably simpler than before. The main changes are:
- As in the new MWE, I added
\myquestion
and a new command \__add_to_grades_list:nn
to add the question/part label and the score to tyhe grade list table
- Instead of using sequences I am now using clists (=comma separated lists) as this works better with the aux file
- the grades data is saved to the auxfile and then read back into
\g_grades_aux_clist
- The grade table is now printed in place
- I am still hard coding the marks for the multiple choice and free response questions but I have added code to save these values to the aux file
- new version that does a bare-hands loop so as to avoid potential issues with overleaf and TeXLive 2019 not yet being ported to ubuntu
After compiling the document once you will find the following lines in the aux file:
\SetGradeList{1a,1,1b,2,2a,4,2b,2,3a,2,3b,4,3c,4,3d,1,4,5}
\SetMultipleChoice{5}
\SetFreeResponse{6}
This the data that is used to construct the grade table.
\SetFreeResponse{6}
Best Answer
Let us add some spice! Here is a not so minimal template which you can adjust to have another design with some bling.