How to control space after a \makebox

This MWE is part of an exam. Before each question I put a box in the left margin that includes the question number and the max score.

For this MWE only, I changed the \makebox into a \framebox to emphasize my problem below.

The question itself (the content) is supposed to start right AT the end of the left margin, so right UNDER the start of the preceding paragraph. My two problems:

1. The box seems to occupy more space than I expect: 1.7cm

2. The box seems to have some space around it, which I don't want.

Obviously I tried to compensate it with negative \hspace, but in more complex real exams, this compensation takes different values, so you keep on adjusting.

How to have a box sized exactly 1.7cm and not more and how to have no space/glue or whatever between the box and the succeeding text?

\documentclass[12pt,a4paper,notitlepage]{report}
\usepackage[left=25mm,right=25mm,top=15mm,height=252mm,includefoot]{geometry}
\usepackage{showframe}              % temporary, to emphasize my point !
\usepackage{xifthen}                % conditionals, booleans

\setlength{\parindent}{0mm}         % no paragraph indentation

\newcounter{countSubExercises}      % number of sub level exercises: a,b,c,...

\newlength{\boxWidth}
\setlength{\boxWidth}{1.7cm}

\newcommand{\newSubEx}[2]
%   #1 = no. of score pts
%   #2 = content
{
\refstepcounter{countSubExercises}  % increment subEx counter
% box with question nr and max score in the left margin
\hspace*{-\boxWidth}
\framebox[\boxWidth][r]{{\tiny\sl #1p}\enspace{\bf\alph{countSubExercises}}\enspace}
#2\\
}

\begin{document}
\chapter*{Exercise title}
A first instructive paragraph\\
\newSubEx{2}{Comment on blah blah ...}
\\
\\
A second instructive paragraph\\
\newSubEx{4}{Calculate the perimeter of ...}
\end{document}

• You are suffering from the very-common %-loss-syndrome. While space inside your code is good for readability, you need to be cautious, as TeX gobbles some spaces but not all. See What is the use of percent signs (%) at the end of lines? – Werner Feb 4 '15 at 19:15
• ...finally, don't use \\ to denote a paragraph break, since it technically doesn't represent a paragraph break. Instead use a blank line in your code, or insert an explicit \par. – Werner Feb 4 '15 at 19:16
• Also, a \framebox introduces its own extra space, as governed by \fboxsep (and of course the rule itself is of thickness \fboxrule). These do not apply for a \makebox. – Steven B. Segletes Feb 5 '15 at 2:19
• Thanks for the initiation @Werner . Adding the % did most of the job. I would never guessed it's relation with my problem! I had already seen several code snippets with the these '%'. Thought it was mainly cosmetic, but there is clearly more to it! – mauricev Feb 7 '15 at 15:43

Since you seem to want a box 1.7cm wide, I guess that the labels (points and letter) should start at 1.7cm from the left margin. So you need to nest a 1.7cm wide box with left alignment into a zero width box with right alignment.

I also added another box for making the letters aligned, compensating for two digit point scores.

Beware of unprotected spaces in your definitions! And don't use \\ as the normal way to end lines/paragraphs.

\documentclass[12pt,a4paper,notitlepage]{report}
\usepackage[left=25mm,right=25mm,top=15mm,height=252mm,includefoot]{geometry}
\usepackage{showframe}              % temporary, to emphasize my point !
\usepackage{xifthen}                % conditionals, booleans

\setlength{\parindent}{0mm}         % no paragraph indentation

\newcounter{countSubExercises}      % number of sub level exercises: a,b,c,...

\newlength{\boxWidth}
\setlength{\boxWidth}{1.7cm}

\newcommand{\newSubEx}[2]{%
%   #1 = no. of score pts
%   #2 = content
\par\medskip
\refstepcounter{countSubExercises}% increment subEx counter
% box with question nr and max score in the left margin
\makebox[0pt][r]{%
\framebox[\boxWidth][l]{% <-------------- change to \makebox
\makebox[1.2em][l]{\tiny\slshape #1p}%
\enspace
\textbf{\alph{countSubExercises}}%
\enspace
}%
}%
#2%
}

\begin{document}
\chapter*{Exercise title}
A first instructive paragraph

\newSubEx{2}{Comment on blah blah ...}

\bigskip

A second instructive paragraph

\newSubEx{4}{Calculate the perimeter of ...}

\bigskip

A third instructive paragraph

\newSubEx{12}{Calculate the perimeter of ...}
\end{document}


• The 'unprotected spaces' seemed to be the main cause. Thanks for the cosmetic improvement on the double digit scores (although rare) – mauricev Feb 7 '15 at 15:46

You can do that with \llap:

\documentclass[12pt,a4paper,notitlepage]{report}
\usepackage[left=25mm,right=25mm,top=15mm,height=252mm,includefoot]{geometry}
\usepackage{showframe} % temporary, to emphasize my point !
\usepackage{xifthen} % conditionals, booleans

\setlength{\parindent}{0mm} % no paragraph indentation

\newcounter{countSubExercises} % number of sub level exercises: a,b,c,...

\newlength{\boxWidth}
\setlength{\boxWidth}{1.7cm}

\newcommand{\newSubEx}[2]
% #1 = no. of score pts
% #2 = content
{
\refstepcounter{countSubExercises} % increment subEx counter
% box with question nr and max score in the left margin
\leavevmode
\llap{\framebox[\boxWidth][r]{{\tiny\sl #1p}\enspace{\bf\alph{countSubExercises}}\enspace}}%
#2\\
}

\begin{document}

\chapter*{Exercise title}
A first instructive paragraph

\newSubEx{2}{Comment on blah blah ...}
\\
\\
A second instructive paragraph

\newSubEx{4}{Calculate the perimeter of ...}

\end{document}


• Oh, no! Not in that position! You were just lucky not to use \newSubEx after a \par. – egreg Feb 4 '15 at 20:54
• @egreg: I confess I didn't check that point. I modified the code, seems to work fine now. – Bernard Feb 4 '15 at 21:02

Enclosing it in \makebox[0pt][r]{..} seems to do the job.

\newcommand{\newSubEx}[2]{\refstepcounter{countSubExercises}%
\makebox[0pt][r]{\framebox[\boxWidth][r]{{\tiny\sl#1p}\enspace{\bfseries
\alph{countSubExercises}}\enspace}}#2\\\relax}


In any case, I think there are cleaner options, with less \\.

Mmmm… or you just needed a % like Werner said… I'm not sure I understood the question. In case this doesn't do what you need, tell me, and I will remove the answer.