Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am typing up a sheet of course problems, and wanted to offset the question numbers from the text of my solutions slightly.

Based upon an answer to this question, I tried adjusting leftskip. The code is below:

\documentclass{article}
\usepackage{amsmath,amsthm,amssymb,amsfonts}
\begin{document}

\noindent 14.5) \\

\setlength{\leftskip}{8mm} \noindent Suppose that $f(a) = f(b)$. This says that $2a + 4 = 2b + 4$, so subtracting \noindent 4 from each side and dividing by 2 yields $a = b$. We conclude that $f$ is injective. \\\\
\noindent Suppose that $c \in E$. This says $2|c $; since $\mathbb{Z}$ distributes multiplication over addition, we have (where $c = 2d$)

\begin{equation*}
c - 4 = 2d - 2(2) = 2(d-2),
\end{equation*}

\vspace{2mm}

 \noindent so $c-4$ is divisible by 2; therefore $\frac{c-4}{2} \in \mathbb{Z}$. But then $f(\frac{c-4}{2})$ clearly equals $c$; so $E \subseteq f[\mathbb{Z}]$. This means that $f$ is surjective. \\\\
 \noindent We conclude that $f$ is a bijection from $\mathbb{Z}$ to $E$. \\

\setlength{\leftskip}{0mm} \noindent 9.10)\\

\setlength{\leftskip}{8mm} \noindent The first statement is false (take $a=3$, $b=8$ to see that there is an integer - namely, 6 - which is in $\mathcal{D}_{ab}$ but not in $\mathcal{D}_a \bigcup \mathcal{D}_b$); the second statement is true, since $p \in \mathcal{PD}_{ab} \implies p \in \mathcal{PD}_a \lor p \in \mathcal{PD}_b$ by Euclid's Lemma (and thus $p \in \mathcal{PD}_a \bigcup \mathcal{PD}_b$), while $p \in \mathcal{PD}_{a} \bigcup \mathcal{PD}_b \implies p|a \lor p|b$, either of which says $p|ab$, so that $p \in \mathcal{PD}_{ab}$. (The second statement follows from these implications.)\\

\setlength{\leftskip}{0mm} \noindent 6.1)\\

\setlength{\leftskip}{8mm} \noindent We show that the $n$ consecutive integers following $(n+1)! + 2$, $n \geq 2$, are composite. Let $S = \{(n+1) + k: 2 \leq k \leq n+1 \}$, and let $K = \{k : 2 \leq k \leq n+1 \}$; it is clear that $S$ is a set of $n$ consecutive integers. Taking any $k$ in $K$, we consider the (obvious) corresponding $s_k = (n+1)! + k \in S$; since $k|(n+1)!$ and $k|k$, we have $k|s_k$; the quotient $\frac{(n+1)!}{k} + 1$ is greater than 1, so each $s_k$ in $S$ thus admits a non-trivial factorization (i.e., is composite). \\

\setlength{\leftskip}{0mm} \noindent 6.2)\\

\setlength{\leftskip}{8mm} \noindent We have 

\begin{eqnarray*}
n^4 + 4 &=& (n^4 + 4n^2 + 4) -4n^2 \\ &=& (n^2 + 2)^2 - (2n)^2\\
&=&(n^2 - 2n + 2)(n^2 + 2n + 2);
\end{eqnarray*}

\vspace{1mm} \noindent both factors are nontrivial for $n \geq 2$. \\

\setlength{\leftskip}{0mm} \noindent 6.5) \\ 
\setlength{\leftskip}{8mm} 

\noindent If we had $d > 1: d|m, n$, then we would have $m = \mu d, n = \nu d$; 

\end{document}

The code was fine for its intended purpose on the first page; however, on the second page, it no longer dedented the question numbers in the way I wanted. (They appeared directly above the solution text, despite my using the same commands as on the first page.)

What's going on here? How can I get my desired effect?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

@user1296727: please don't take the following remarks personally; one learns from one's own errors and you, as a teacher, know this well. :-)


This is completely against LaTeX philosophy, where logical structures should be marked and then their typesetting can be defined once and for all of them.

Here's a proposal.

\documentclass{article}
\usepackage{amsmath,amsthm,amssymb,amsfonts}

\newcommand{\relor}{\mathrel{\lor}}
\newcommand{\divis}{\,|\,}
\newenvironment{solution}[1]
  {\par\addvspace{\medskipamount}
   \noindent\makebox[0pt][r]{#1) }\ignorespaces}
  {\par\addvspace{\medskipamount}}

\begin{document}

\begin{solution}{14.5}
Suppose that $f(a) = f(b)$. This says that $2a + 4 = 2b + 4$, so subtracting $4$ 
from each side and dividing by $2$ yields $a = b$. We conclude that $f$ is injective.

Suppose that $c \in E$. This says $2\divis c$; since $\mathbb{Z}$ distributes 
multiplication over addition, we have (where $c = 2d$)
\begin{equation*}
c - 4 = 2d - 2(2) = 2(d-2),
\end{equation*}
so $c-4$ is divisible by $2$; therefore $\frac{c-4}{2} \in \mathbb{Z}$. 
But then $f(\frac{c-4}{2})$ clearly equals $c$; so $E \subseteq f[\mathbb{Z}]$. 
This means that $f$ is surjective. 

We conclude that $f$ is a bijection from $\mathbb{Z}$ to $E$.
\end{solution}

\begin{solution}{9.10}
The first statement is false (take $a=3$, $b=8$ to see that there is an 
integer --~namely, 6~-- which is in $\mathcal{D}_{ab}$ but not in 
$\mathcal{D}_a \cup \mathcal{D}_b$); the second statement is true, 
since $p \in \mathcal{PD}_{ab} \implies p \in \mathcal{PD}_a \relor p \in \mathcal{PD}_b$ 
by Euclid's Lemma (and thus $p \in \mathcal{PD}_a \cup \mathcal{PD}_b$), while 
$p \in \mathcal{PD}_{a} \cup \mathcal{PD}_b \implies p\divis a \relor p\divis b$, either of which 
says $p\divis ab$, so that $p \in \mathcal{PD}_{ab}$. (The second statement follows from 
these implications.)
\end{solution}

\begin{solution}{6.1}
We show that the $n$ consecutive integers following $(n+1)! + 2$, $n \geq 2$, are 
composite. Let $S = \{(n+1) + k: 2 \leq k \leq n+1 \}$, and let 
$K = \{k : 2 \leq k \leq n+1 \}$; it is clear that $S$ is a set of $n$ consecutive 
integers. Taking any $k$ in $K$, we consider the (obvious) corresponding 
$s_k = (n+1)! + k \in S$; since $k\divis(n+1)!$ and $k\divis k$, we have $k\divis s_k$;
the quotient $\frac{(n+1)!}{k} + 1$ is greater than 1, so each $s_k$ in $S$ thus 
admits a non-trivial factorization (i.e., is composite).
\end{solution}

\begin{solution}{6.2}
We have 
\begin{align*}
n^4 + 4 &= (n^4 + 4n^2 + 4) -4n^2 \\
&= (n^2 + 2)^2 - (2n)^2\\
&= (n^2 - 2n + 2)(n^2 + 2n + 2);
\end{align*}
both factors are nontrivial for $n \geq 2$.
\end{solution}

\begin{solution}{6.5}
If we had $d > 1: d\divis m, n$, then we would have $m = \mu d, n = \nu d$; 
\end{solution}

\end{document}

There is much less white space, but the numbers in the margin stick out and this is sufficient to give the required emphasis.

Notice the definitions of \divis and \relor: padding the bar with some space helps in distinguishing the object; you're using \lor as a relation symbol, so it's best to tell LaTeX it is.

Never use \\ for producing white vertical space and never separate displayed equations from the text above them; it depends on the text whether it should be separated with a blank line from the text below it.

enter image description here


How do we get the labels in the margin? The solution environment wants the label as its argument; then it does \par to be sure about LaTeX's state and adds a vertical spacing (read on for \addvspace). The paragraph is started by \noindent, followed by a box of zero width with its contents pushed to its right margin: since there is no space, the text will stick out on the left.

The \ignorespaces is needed because otherwise the end-of-line in

\begin{solution}{14.5}

would create an extra space which would go in front of "Suppose"; so we kill it.

At the end of the environment, \par ends whatever paragraph was being built and issues another vertical space. However, \addvspace is used, so two consecutive solution environments will be separated by just one of those vertical spaces. In general, when two \addvspace are next to each other, the maximum amoung wins.


If you prefer that the solution text is indented (which I don't recommend), you can use the same code as before, just changing the definition of solution, for example with the help of the enumitem package:

\usepackage{enumitem}
\newlength{\sollabel}
\AtBeginDocument{
  \settowidth{\sollabel}{00.00) }
}
\newenvironment{solution}[1]
  {\begin{itemize}[leftmargin=\sollabel,labelwidth=*]\item[#1)]}
  {\end{itemize}}

This should show why it's better to use "logical structures", instead of marking manually the spacings and everything else. A mock paragraph has been added to show the result.

enter image description here


About \leftskip: TeX typesets a paragraph with only one value of \leftskip, namely the one which is current at the end of the paragraph. With

\setlength{\leftskip}{0mm} \noindent 6.5) \\ 
\setlength{\leftskip}{8mm} 

\noindent If we had $d > 1: d|m, n$, then we would have $m = \mu d, n = \nu d$; 

the paragraph ends at the empty line after \setlength{\leftskip}{8mm}, because \\ doesn't end paragraphs. In the original code there's an empty line before \setlength{\leftskip}{8mm} in the other cases.

share|improve this answer
    
Purely for interest, why doesn't the \leftskip take effect at the start of the second page in the OP's example? –  Ian Thompson Oct 17 '12 at 10:54
    
Could you explain how the environment which you defined allowed you to attach the labels which you did, and what the parameters in your definition mean? –  user1296727 Oct 17 '12 at 11:01
    
OK I get it now. The change to leftskip does take effect, and everything on the second page is indented, which makes it look at first glance as though nothing is indented. –  Ian Thompson Oct 17 '12 at 14:48

I'm not sure why this happens, but what is clear is that this is a very awkward method. Surely you would be off better using an itemize environment (see section 2.11.1 of the Not so Short Guide to LaTeX for details). In my opinion, starting the text below the numbers does not look very good. Nevertheless, it is not difficult to achieve this.

\documentclass{article}
\newcommand\dropitem[1]{\item[#1]\leavevmode\vskip1em}
\begin{document}
\begin{itemize}
\dropitem{14.5)} Some material that is more than one line long, so we can see
                 that the indentation is still correct.
\dropitem{9.10)} More stuff
\end{itemize}
\end{document}
share|improve this answer

Your Answer

 
discard

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.