# How can I make the dotted lines go all the way to the margin?

In the exam package, I'm trying to put in writing space in the form of dotted lines. To do so, I created the command "\lines{X}" to insert X amount of dotted lines on the page at a set spacing that goes like this:

\newcommand{\lines}[1]{

\foreach \n in {1,...,#1}{
\parbox[b][2em][b]{\linewidth}{\dotfill}
}


However, when used, the following shows up for:

    \newgeometry{
margin=2.35146cm,
bottom=2.5cm,
marginparsep=0mm
}
\textbf{20 marks\\
Attempt Question 1\\
Allow about 45 minutes for this section}

Read the texts on pages 2–7 of the Stimulus Booklet carefully and then answer the question
in the spaces provided. These spaces provide guidance for the expected length of response.

\begin{bookletquestion}{3}

\textbf{Text 1 — Poem}

Analyse how Langston Hughes uses visual imagery to express his emotions.

\lines{6}


How come the dotfill does not go all the way to the margin and match the length of the section header and how can I modify it so it does?

For reference, here is the "behind the scenes" of my document with my failed example being set in the "bookletquestion" environment

\ProvidesPackage{exam}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{anyfontsize}
\usepackage{asymptote}
\usepackage{changepage}
\usepackage{color}
\usepackage{enumitem}
\usepackage{fancyhdr}
\usepackage{framed}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{helvet}
\usepackage{marginnote}
\usepackage{mathptmx}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{pgffor}
\usepackage{setspace}
\usepackage{tikz}
\usepackage{totalcount}
\usepackage{accents}
\usepackage{pifont}

\newcounter{QuestionCounter}
\setcounter{QuestionCounter}{1}

\geometry{
a4paper,
margin=2cm,
bottom=2.5cm,
marginparsep=0mm
}

\pagestyle{fancy}

\setlength{\parindent}{0em}
\setlength{\parskip}{1em}

\renewcommand\labelitemi{$\vcenter{\hbox{\tiny$\bullet$}}$}

\setlist[itemize]{
itemsep=-0.2em,
align=parleft,
leftmargin=1em,
labelwidth=0.5em
}

\newcommand{\mrks}[1]{\marginnote{\textbf{#1}}[0em]\ignorespaces}

\renewcommand{\labelenumi}{(\roman{enumi})}

\setlist[enumerate]{
align=parleft,
labelindent=0em,
parsep=0.5em
}

\setlist[enumerate,1]{
itemsep=2em
}

\setlist[enumerate,2]{
align=right,
itemsep=1em,
topsep=1em,
labelsep=1em
}
}{
}

\newenvironment{shortquestion}[1]{
\textbf{Question \theQuestionCounter} (#1 marks)

}{
\stepcounter{QuestionCounter}
}

\newenvironment{bookletquestion}[1]{
\textbf{Question \theQuestionCounter} (#1 marks)

}{
\stepcounter{QuestionCounter}
}

\newcommand{\nextpage}{\the\numexpr\thepage+1}

\newcommand{\questionbreak}{
\end{enumerate}
\begin{center}
\textbf{Question \theQuestionCounter\ continues on page \nextpage}
\end{center}
\pagebreak
Question \theQuestionCounter\ (continued)
\begin{enumerate}[resume]
}

\newcommand{\centerbold}[1]{
\begin{center}\textbf{#1}\end{center}
}

\newcommand{\questionend}{
\vspace{1em}
\centerbold{End of Question \theQuestionCounter}
}

\newcommand{\lines}[1]{

\foreach \n in {1,...,#1}{
\parbox[b][2em][b]{\linewidth}{\dotfill}
}
}

\large{\textbf{#1}}

\normalsize
}{
\\ \rule{\textwidth}{1pt}}

• Please post a minimal working example as a complete document that can be compiled as is. Don't make us guess what document class you're using with what options, what other packages, how various environments are defined, etc. As is, I am having trouble duplicating your result. Sep 23 at 2:17
• @frabjous Is what I've added enough as a minimal working example? Sep 23 at 2:43
• It's not a minimal working example. You apparently didn't read the link. However, it does clarify the problem. I'll post an answer. Sep 23 at 3:24
• Exam class handles the page geometry internally and does not play well with the geometry package. Sep 23 at 14:40

You have those dotted lines inside a shortanswer environment. The exam.sty file defines this environment so that it puts its contents inside \begin{adjustwidth}{}{10mm} ... \end{adjustwidth}, an environment defined by the changepage package. This has the effect of increasing the margin on the right side inside that environment by 10mm, which are why the lines don't go all the way to the usual margin.

One option would be to take the adjustwidth environment out of the definition and use this instead:

\newenvironment{shortanswer}{

\renewcommand{\labelenumi}{(\roman{enumi})}

\setlist[enumerate]{
align=parleft,
labelindent=0em,
parsep=0.5em
}

\setlist[enumerate,1]{
itemsep=2em
}

\setlist[enumerate,2]{
align=right,
itemsep=1em,
topsep=1em,
labelsep=1em
}
}{}


(You can use the same definition with \renewenvironment in your document's preamble if you don't want to change the .sty file.)

However, if this is your package, it's unclear why that's there to begin with if you didn't want to increase the margin.

If, for some reason you do want the margin increased in that environment for everything except the dotted lines, you could change the definition of \lines to use \textwidth rather than linewidth, since the adjustwidth environment only changes the latter.

\newcommand{\lines}[1]{

\foreach \n in {1,...,#1}{
\parbox[b][2em][b]{\textwidth}{\dotfill}
}
}


Then the lines will be wider than any text (if you put any in there wide enough to wrap) inside that environment.

Take note, however, that this will produce a number of "overfull \hbox" warnings in the log file since the dotted lines are too large for what is considered the margins in that section. I guess they can be ignored if you're sure that's what you want.

That seems a bit odd to me. I'd either use the first solution, or just move the lines outside the environment to begin with if they don't belong there.