4

I am working on preparing a document in latex, and I need to define an new environment as follow:

When the code is:

\begin{IF}
    the sum of $a$, $b$, and $c$ is 10,\\
    the product of $a$, $b$, and $c$ is 14,\\
    the sum of squares of $a$, $b$, and $c$ is 54;
\end{IF}

It is displayed like this:

IF: the sum of a, b and c is 10, 
    the product of a, b, and c is 14;
    the sum of squares of a, b, and c is 54;

Note that:

  1. the first sentence of the body is preceded by the keyword "IF", i.e., they are in the same line.
  2. these three sentences in the body are left-aligned.

Can you help me define this IF-environment? Thankssssssss!!

5

Here's one option using a list with the help of enumitem:

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

\newlength\mylen
\AtBeginDocument{\settowidth\mylen{IF:~}}

\newlist{MIF}{description}{1}
\setlist[MIF,1]{leftmargin=*,labelsep=0pt,itemindent=-\mylen}
\newenvironment{IF}
  {\begin{MIF}\item[\textnormal{IF:~}]}
  {\end{MIF}}

\begin{document}

\lipsum[4]
\begin{IF}
  the sum of $a$, $b$, and $c$ is 10,\\
  the product of $a$, $b$, and $c$ is 14,\\
  the sum of squares of $a$, $b$, and $c$ is 54;
\end{IF}
\lipsum[4]

\end{document}

The result:

enter image description here

  • \AtBeginDocument{\setlength}{\mylen}{IF:~}} – egreg Aug 9 '15 at 8:51

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.