1

For my homework questions, I have multiple questions which present proof-type and standard solution-type answers. So as something similar to the standard amsthm \begin{proof}....\end{proof} environment, I have defined a new environment within my Macro package for a solution environment as follows:

\newenvironment{soln}{%
    \noindent\par\textbf{Solution:}}{\par\medskip
}

However, I noticed that when I had included a figure within the standard amsthm proof environment, the figures would align and indent correctly within the environment, so that a figure caption for example would center within the environment and not just within the document. An example of this is here: aligned figure in amsthm environment

This screenshot was produced with the following code:

\begin{proof}
    The required vector plot is as follows,
    \begin{figure}[H]
        \caption{Plot of vectors at each of the points (see Legend for details)}
        \centering
        \includegraphics[scale=0.25]{5a.jpeg}
    \end{figure}
\end{proof}

However, within my new solution environment with the following code:

\begin{soln}
    \begin{figure}[H]
        \caption{Plot of the slope field and solution curves for $(1, 1)$ and $(1.25, 1.25)$}
        \centering
        \includegraphics[scale=0.25]{5c.png}
    \end{figure}
\end{soln}

I get the following screenshot instead: example of problem

The problem here is that the figure hasn't aligned with the word 'Solution' in the same way that it aligns with the word 'Proof' in the amsthm environment. I'm wondering what I can do to fix this, if it's a problem with the way I've set out my code for figures or if it's a problem with the way my environment works. I'm still pretty new to latex and working out how the spacing and margins works, so a bit of an explanation would be really helpful to me (as well as a solution). Thanks in advance!

Edit: It is worth noting that this error occurs inside an itemize environment and the document class is \documentclass[12pt]{article} and the following settings in my preamble \parindent = 0mm, \parskip = 2mm, \pagestyle{empty} if potentially that's messing with the indenting.

Edit 2: Here is a proper worked example to demonstrate the issue:

\documentclass[12pt]{article}

\usepackage{amsthm, amssymb, amsmath, enumerate, mathtools, enumitem}
\usepackage{graphicx}
\usepackage{float}

\graphicspath{{./Images/}}

\newenvironment{soln}{%
    \par\noindent\textbf{Solution:}}{\par\medskip
}

\setlength{\textwidth}{168.0truemm}
\setlength{\textheight}{265.0truemm}
\setlength{\oddsidemargin}{-4.0mm}
\setlength{\evensidemargin}{-4.0mm}
\setlength{\topmargin}{-22.0truemm}
\parindent=0mm
\parskip=2mm
%%%\parskip=1.5mm
\pagestyle{empty}

\begin{document}

\begin{itemize}
\item[{\bf 1}]
    \begin{itemize}
        \item[a)] This is the first figure:
            \begin{proof} 
                Here is where I put my first figure
                \begin{figure}[H]
                    \caption{Plot of vectors at each of the points (see Legend for details)}
                    \centering
                    \includegraphics[scale=0.25]{5a.jpeg}
                \end{figure}
            \end{proof}
\newpage
        \item[b)] This is the second figure:
            \begin{soln}
                Here is where I put my second figure:
                \begin{figure}[H]
                    \caption{Plot of the slope field and solution curves for $(1, 1)$ and $(1.25, 1.25)$}
                    \centering
                    \includegraphics[scale=0.25]{5c.png}
                \end{figure}
            \end{soln}
    \end{itemize}
\end{itemize}
\end{document}

However, I have actually managed to find the problem myself. It seems my caption title is too long so it's not aligning strictly at the solution point. Furthermore, the caption title for the figure isn't actually aligning to space set out by the itemize environment within each item. It's as if the figure is centering to the document center instead of the slightly indented center within the itemize environment.

6
  • Please turn this into a minimal working example (MWE), so we don't have to piece together the bits that you've shown us.
    – Teepeemm
    Sep 21 at 1:55
  • You start out your definition with \noindent \par. The \par wipes out the \noindent, so when the ext begins it will be indented to the distance of \parindent. Although you've said that is set to zero, there isn't enough code in context to check what's really happening. Sep 21 at 2:07
  • @barbarabeeton: probably this is because the op is in an itemize so that \listparindent is in effect, which is not touched by \setlength{\parindent}{0mm}. Sep 21 at 2:10
  • @Teepeemm Added a proper MWE, and a few edits.
    – Ammardian
    Sep 21 at 4:29
  • \begin{figure}...\end{figure} are floats; even though you specified [H], their original intent is for them to move around and fit into wherever there is space. In particular, it would make no sense for floating figures to obey "local indentation" rules. Sep 21 at 6:23

3 Answers 3

4

When TeX interprets \noindent\par in vertical mode then it opens the paragraph with no indentation box (\noindent) and it immediately closes this empty paragraph (\par). The paragraph has no lines (there is no the last paragraph line, this is an exception), so no lines are put to the outer vertical list. Only \parskip value is inserted here. Then you have \textbf{Solution:}, so the S letter opens a new paragraph with normal indentation box. The result is: the word Solution is indented (and a second \parskip value is above it).

What you want to do is \noindent imediatelly followed by \textbf{Solution:}. Then the paragraph is opened by \noindent (without indentation box) and the letter S is typeset inside this paragraph in horizontal mode.

TeX users should know the principles about horizontal mode, vertical mode. See, for example, TeX in a Nutshell, section 5.

2

Use enumitem features for the lists, not hand numbering. Don't load also enumerate, it's not compatible with enumitem.

Also, avoid [H]. With a minipage and \captionof you get the same and you can ensure that the environment fits in the current line width.

\documentclass[12pt]{article}

\usepackage{amsthm, amssymb, amsmath, mathtools, enumitem}
\usepackage{graphicx}
\usepackage[
  textwidth=168mm,
  textheight=265mm,
]{geometry}
\usepackage{caption}

\usepackage{showframe}

\graphicspath{{./Images/}}

\newenvironment{soln}{%
    \par\noindent\textbf{Solution:}}{\par\medskip
}

%\setlength{\textwidth}{168.0truemm}
%\setlength{\textheight}{265.0truemm}
%\setlength{\oddsidemargin}{-4.0mm}
%\setlength{\evensidemargin}{-4.0mm}
%\setlength{\topmargin}{-22.0truemm}
\setlength{\parindent}{0mm}
\setlength{\parskip}{2mm plus 0.1pt}

\captionsetup[figure]{position=top}

\pagestyle{empty}

\begin{document}

\begin{enumerate}[label=\bfseries\arabic*]
\item
  \begin{enumerate}[label=\alph*)]
  \item This is the first figure:
    \begin{proof} 
    Here is where I put my first figure

    \begin{minipage}{\linewidth}
      \centering

      \captionof{figure}{Plot of vectors at each of the points (see Legend for details)}

      \includegraphics[scale=0.25]{example-image}
    \end{minipage}
    \end{proof}

  \item This is the second figure:
    \begin{soln}
    Here is where I put my second figure:

    \begin{minipage}{\linewidth}
      \centering

      \captionof{figure}{Plot of the slope field and solution curves
        for $(1, 1)$ and $(1.25, 1.25)$}

      \includegraphics[scale=0.25]{example-image}
    \end{minipage}
    \end{soln}

  \item This is the third figure:
    \begin{soln}
    Here is where I put my second figure:

    \begin{minipage}{\linewidth}
      \centering

      \captionof{figure}{Plot of the slope field and solution curves
        for $(1, 1)$ and $(1.25, 1.25)$ and some more text to see what happens
        when the caption has to wrap across lines}

      \includegraphics[scale=0.25]{example-image}
    \end{minipage}
    \end{soln}
  \end{enumerate}
\end{enumerate}

\end{document}

The showframe package is just for showing the boundaries of the text block, remove it.

enter image description here

1

I admit I am not 100% sure what your question is. The standard proof environment does not indent anything. The word "Proof" appears left justified with no indentation. However, the soln environment you defined does. See the following screenshot, which explains the difference in behavior.

enter image description here

If I am interpreting your intent right, the issue is that you defined the soln environment with

\noindent\par\textbf{Solution:}

In this order, TeX first processes the \noindent, but then hits \par which starts a new paragraph and the \noindent is forgotten. If you want to start a new paragraph with no indentation, you should use instead

\par\noindent\textbf{Solution:}

So that it will open a new paragraph, set \noindent, and thus print "Solution" flushleft.

(And no, figures are a complete red herring here.)


Finally, I would suggest the following alternative definition using the optional argument to proof; this way you also get a tombstone symbol and make it behave exactly like proof would.

\documentclass{amsart}
\usepackage{lipsum}  %only used to generate blind text

\newenvironment{soln}[1][Solution]{%
\begin{proof}[{\normalfont\bfseries#1}]}{\end{proof}}

\begin{document}
\begin{soln}[Solution of Question 1]
        Test
\end{soln}

\begin{soln}
        \lipsum[1-2]
\end{soln}
\end{document}

enter image description here

2
  • 1
    As to why your environment definition seems to work until you start putting things in an itemize, see my other comment. Sep 21 at 2:11
  • I added a proper working example now, and it seems to actually be the length of the caption title that is messing with the indentation. But in other places It has fixed some of the strange indentation that it was going through before.
    – Ammardian
    Sep 21 at 4:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .