1

I am trying to create a command that allows me (or the user) to switch between two different styles for typesetting problems. One is the runin in the margin, while the other one is defined by subsection

  • Is there a simple way to obtain consistent spacing for the two styles?
  • In particular I want the runin style to start on the same line regardless of whether there is a blank line below or not. Also it would be nice if the space before \problem was the same regardless of style.

As can be seen in the image the second problem has a newline too much.

enter image description here

Is there a way for

\Problem
\lipsum[66]

and

\Problem

\lipsum[66]

to produce the same output?

  • While not really the question the same output would be great in an enumerate environment. However, I was not able to emulate the \subsection apperance using a \item.

Code

\documentclass{article}
\usepackage{lipsum}
\usepackage{enumitem}
\usepackage{etoolbox}

\newtoggle{inline} \settoggle{inline}{true}

\newcounter{problem}
\newcommand{\Problem}{%
    \stepcounter{problem}%
    \iftoggle{inline}{%
        \bigskip

        \noindent\makebox[0pt][r]{\protect\fbox{\theproblem}\qquad}%
        %\vspace{-\baselineskip}
        }{%
        \subsection*{Problem~\theproblem}%
    }%
}

\setlength\parindent{0pt}

\begin{document}

\Problem
\lipsum[66]

\Problem

\lipsum[66]

\settoggle{inline}{false}

\Problem

\lipsum[66]

\Problem
\lipsum[66]

\end{document}
1
  • \section etc. use \@afterheading to affect the next paragraph. Nov 19 '19 at 17:07
2

Two \pars act the same as one \par (blank line).

\documentclass{article}
\usepackage{lipsum}
\usepackage{enumitem}
\usepackage{etoolbox}

\newtoggle{inline} \settoggle{inline}{true}

\newcounter{problem}
\newcommand{\Problem}{%
    \stepcounter{problem}%
    \iftoggle{inline}{%
        \bigskip\par
        \noindent\makebox[0pt][r]{\protect\fbox{\theproblem}\qquad}%
        \par\vskip-\baselineskip\vskip-\parskip
        }{%
        \subsection*{Problem~\theproblem}%
    }%
}

\setlength\parindent{0pt}

\begin{document}

\Problem
\lipsum[66]

\Problem

\lipsum[66]

\settoggle{inline}{false}

\Problem

\lipsum[66]

\Problem
\lipsum[66]

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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