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 need help writing an Example environment. I just want it to look like the figure below which I took from an old book I have in my library.

enter image description here

This is what I have done.

    \newtheorem{exem}{EXAMPLE}

    \newenvironment{ex}{\parshape=3
    0\textwidth \textwidth
    0.25\textwidth 0.74\textwidth
    0pt \textwidth \begin{exem} \rm \hspace{0.2cm}}{\end{exem}}

    \begin{document}
        \begin{ex}
        Text
        \end{ex}
    \end{document} 

However this code fails when the text is very long in the defined environment. Then I start having problems with right margin. I have no idea how to solve it. Please, can you help me to define that environment?

share|improve this question
    
Welcome to TeX.SX! Questions about how to draw specific graphics that just post an image of the desired result would be greatly improved by adding a MWE. Please post a minimal compilable document showing that you've tried to produce the image and then people will be more disposed to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. –  Adam Liter Dec 24 '13 at 23:57
add comment

1 Answer

up vote 11 down vote accepted

Here is an example environment that sets the paragraph alignment/shape using \parshape:

enter image description here

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\newcounter{example}
\newcommand{\examplename}{\textsc{Example}}
\makeatletter
\newenvironment{example}
  {\refstepcounter{example}% Step example counter
   \sbox\@tempboxa{\examplename~\theexample.~}% Store environment title
   % Set paragraph alignment
   \parshape 3 \wd\@tempboxa \dimexpr\linewidth-\wd\@tempboxa % Line 1
     \wd\@tempboxa \dimexpr\linewidth-\wd\@tempboxa % Line 2
     0pt \linewidth% Line 3+
    \noindent% No indent
    \leavevmode% Start paragraph
    \llap{\usebox\@tempboxa}% Insert environment title
    \ignorespaces}% Remove spaces
  {\par}
\begin{document}
\lipsum[1]
\begin{example}
  \lipsum[2]
\end{example}
\lipsum[3]
\begin{example}
  Some example content
\end{example}
\begin{example}
  Some more example content
\end{example}
\lipsum[4]
\end{document}
share|improve this answer
    
Thank you for your answer! It really works for me. –  limber Dec 25 '13 at 1:47
1  
@limber Instead of---or in addition to---posting a “Thank you” as a comment, you should thank Werner by upvoting his answer (with the upward pointing arrow to the left of it; you need 15 reputation points before you can upvote) and accepting it (by clicking on the checkmark ✓). –  Adam Liter Dec 25 '13 at 2:41
add comment

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.