[Tex/LaTex] How to control space after a \makebox

spacing

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}

Best Answer

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}

enter image description here

Related Question