2

Consider the following :

\documentclass[12pt]{report}
\usepackage{amsmath, amssymb, amsthm}
\usepackage{lipsum}

\usepackage{tikz}
\usetikzlibrary{shadows}
\newcommand*\squared[1]{\tikz[baseline=(char.base)]{\node[shape=rectangle, draw, inner color = white, drop shadow = {opaque, black}, inner sep=3pt, text justified] (char) {#1};}}

\newtheoremstyle{exercise}
  {\topsep}
  {\topsep}
  {\hangindent=2em}
  {}
  {}
  {}
  {.8em}
  {\squared{\thmnumber{#2}}}

\theoremstyle{exercise}
\newtheorem{exercise}{}

\renewcommand{\arraystretch}{1.75}
\usepackage{tabularx}

\begin{document}

\begin{exercise}
    \begin{tabularx}{\textwidth}[t]{r @{\hskip .4em} X}
        a) & This is a test. \\
        b) & I say
        $$
            \pi \approx 3.14.
        $$ \\
        c) & Do you agree?
    \end{tabularx}
\end{exercise}

\end{document}

It seems like the fact that b) finishes with math mode adds extra vertical spacing before c). But I would like the spacing to be uniform. That is, I want the same vertical space before b) and before c). How to do it ?

5
  • off topic: don't use $$ $$. Use \[ \] instead.
    – Sigur
    Commented Jul 28, 2014 at 0:32
  • @Sigur Why ? I've always used $$ $$ and it has never done anything bad up to this date.
    – Amateur
    Commented Jul 28, 2014 at 0:33
  • 1
    see here: tex.stackexchange.com/questions/503/why-is-preferable-to
    – Sigur
    Commented Jul 28, 2014 at 0:36
  • Use an optional argument to line break after the math: \[ \pi \approx 3.14 \] \\[-1.75\belowdisplayskip]
    – Sigur
    Commented Jul 28, 2014 at 0:39
  • I don't know what is the exactly value used in line breaks. My suggestion looks nice but note that you are using another value to \arraystretch so I used 1.75.
    – Sigur
    Commented Jul 28, 2014 at 0:41

1 Answer 1

3

You have few options.

First one is to add the equation in a row of its own:

\documentclass[12pt]{report}
\usepackage{amsmath, amssymb, amsthm}
\usepackage{lipsum}

\usepackage{tikz}
\usetikzlibrary{shadows}
\newcommand*\squared[1]{\tikz[baseline=(char.base)]{\node[shape=rectangle, draw, inner color = white, drop shadow = {opaque, black}, inner sep=3pt, text justified] (char) {#1};}}

\newtheoremstyle{exercise}
  {\topsep}
  {\topsep}
  {\hangindent=2em}
  {}
  {}
  {}
  {.8em}
  {\squared{\thmnumber{#2}}}

\theoremstyle{exercise}
\newtheorem{exercise}{}

\renewcommand{\arraystretch}{1.75}
\usepackage{tabularx}

\begin{document}

\begin{exercise}
    \begin{tabularx}{\textwidth}[t]{r @{\hskip .4em} X}
        a) & This is a test. \\
        b) & I say \\
           &
            \hfil $\pi \approx 3.14$.
            \\
        c) & Do you agree?
    \end{tabularx}
\end{exercise}
\end{document}

enter image description here

However, I feel that a list enumerate would be the better way to go after some modifications to the exercise environment.

Here is some more additions. These are not perfect as the \arraystretch is modified and the widths of \parbox and \minipage are not accurately calculated. Nevertheless, it may serve as a starting point.

\documentclass[12pt]{report}
\usepackage{amsmath, amssymb, amsthm}
\usepackage{lipsum}

\usepackage{tikz}
\usetikzlibrary{shadows}
\newcommand*\squared[1]{\tikz[baseline=(char.base)]{\node[shape=rectangle, draw, inner color = white, drop shadow = {opaque, black}, inner sep=3pt, text justified] (char) {#1};}}

\newtheoremstyle{exercise}
  {\topsep}
  {\topsep}
  {\hangindent=2em}
  {}
  {}
  {}
  {.8em}
  {\squared{\thmnumber{#2}}}

\theoremstyle{exercise}
\newtheorem{exercise}{}

\renewcommand{\arraystretch}{1.75}
\usepackage{tabularx,enumitem,showframe}

\begin{document}

\begin{exercise}
    \begin{tabularx}{\dimexpr\textwidth-2.8em\relax}[t]{@{\,}r @{\hskip .4em} X}
        a) & This is a test. \\
        b) & I say \parbox[t]{0.88\linewidth}{%
           \[
            π\approx 3.14.
           \]
           }\\
        c) & Do you agree?
    \end{tabularx}
\end{exercise}
\begin{exercise}
    \begin{minipage}[t]{0.928\linewidth}
     \begin{enumerate}[label = \alph*),leftmargin=*,topsep=0pt,partopsep=0pt]
        \item This is a test.
        \item I say
           \[
            π\approx 3.14.
            \]
        \item Do you agree?
    \end{enumerate}
    \end{minipage}%
\end{exercise}
\end{document}
4
  • So simple and clear.
    – Sigur
    Commented Jul 28, 2014 at 0:47
  • @HarishKumar But then the spacing before the math mode will be that of the array, which may differ from other parts of the text not in an array ?
    – Amateur
    Commented Jul 28, 2014 at 0:53
  • @Amateur True, but you want same spacing. As a remedy, try enclosing the equation inside a \parbox and use \[...\]
    – user11232
    Commented Jul 28, 2014 at 1:27
  • @HarishKumar Thanks for the idea. I've also tried to use a list enumerate, as you suggested. But the \hangindent won't work on the list. Is that why you say "after some modifications to the exercise environment" ?
    – Amateur
    Commented Jul 28, 2014 at 1:29

You must log in to answer this question.

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