TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to design a custom question\solution environment for homework assignments (I'm aware of the exam class but I am choosing to try and make my own) and am having problems with the alignment.

I've set my minipage to use \linewidth for its width, but that extends beyond the right margin, as is shown in my MWE. Is there any way I can make it so that it fills to the right margin without having to set specific lengths? I may change my document margins at a later time and I don't want to have to also change the width of the minipage.

Also, as can be seen, problems are indented quite far over from the left margin, and I'd prefer them to be a tad closer. How can I go about achieving this?



\newcommand{\@coursenumber}{{\em No \textbackslash coursenumber specified}}
\newcommand{\@semester}{{\em No \textbackslash semester specified}}
\newcommand{\@studentname}{{\em \textbackslash studentname unknown}}
\newcommand{\@studentid}{{\em \textbackslash studentid unknown}}
\newcommand{\@school}{{\em \textbackslash school unknown}}
\newcommand{\@department}{{\em \textbackslash department unknown}}
\newcommand{\@lecture}{\textbackslash lecture}

\newcommand{\solutionstext}{\bfseries (Solutions)}

% These commands follow the titling package format for titles
% They define user commands to format the subtitle
% This command takes the subtitle as its argument, and uses the titling command
% \maketitlehookb plus the previously defined formatting commands to insert
% the subtitle into the titlepage. It also generates \thesubtitle for subsequent use
% Now we define the formatting for the subtitle
\presubtitle{\begin{center}\Large} % change this as needed

% These commands set up the headers. They are set up for even and odd pages the same
% Check the fancyhdr documentation for information on how to set them differently
% for odd and even pages
\lhead{\begin{tabular}{@{}l}\@coursenumber\ (\@semester)\\\@studentname\ (\@studentid)\end{tabular}}
\rhead{\begin{tabular}{r@{}}Assignment \#\@lecture\\\today\end{tabular}}
% Set the width of the header rule. Make 0pt to remove the rule.
% Make the head height match the size of the header


    \arabic{problem}. & \textbf{#1}\\[1mm]
    & \hfill




  \begin{problem}{Problem Title}


  \begin{problem}{Problem 2}
share|improve this question
From the looks of it, you are creating a tabular with a first column that is 3mm wide and a second with your minipage that is \linewidth wide. It probably runs in the margin by 3mm + the inter-column spacing. Set the inter-column spacing to what you want (e.g. @{\hspace*{1mm}} between the column specifications of \begin{tabular}) and calculate the right width of the second column by removing those lengths from \linewidth. – Xavier Feb 3 '13 at 5:16
up vote 2 down vote accepted


    \arabic{problem}. & \textbf{#1}\\[1mm]
    &       \BODY

When you reach the double digit problems, you have to change the length 3mm to 5mm though. In that case, you may be interested in something like:


    \arabic{problem}. & \textbf{#1}\\[1mm]
    &       \BODY
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.