2

I'm already using tcolorbox for my theorems, so a solution based on that package would be ideal.

This is more or less what I had in mind: enter image description here

EDIT: Just to clarify, the two lines of text beside the title are not independent from the rest. Everything from the lipsum is the content of the theorem.

EDIT 2: I updated the example to reflect how I would like the title to appear. It should read "this is the example's title", I got confused!

  • 1
    Is the two lines text beside the title independent from the rest? Do you want something like wrapfig? – Ignasi Mar 14 '17 at 17:45
  • Using @Ignasi's suggestion: A wrapfigure environment where the tcolorbox mimes the title, i.e. something like here: tex.stackexchange.com/questions/358298/… – user31729 Mar 14 '17 at 17:51
  • Thanks a lot, I updated the question. No the two lines of text are part of the rest. I just realized that I didn't address where the title, if any, should be. I would prefer the title to be merged with where the lipsum is, I'll make an example when I'm on my computer. Regarding the wrapfigure, this looks like the way to go. I'll have a look at it soon. Note however that in the particular example that @Christian links to, the text that wraps around the theorem environment, is not the content of the theorem. In my example, I would like the content of the theorem to wrap around the title. – geo909 Mar 14 '17 at 18:21
  • I updated the example to show where the title should be – geo909 Mar 14 '17 at 19:04
4

Here is a solution with ntheorem. I define a wrap theorem style, which simply uses \hangindent and \hangafter:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage[thmmarks, amsmath, thref]{ntheorem}

\makeatletter
\newlength{\wrapboxlg}
\newtheoremstyle{wrap}%%
  {\item[\hskip\labelsep\Large\theorem@headerfont ##1~##2\theorem@separator]
\mbox{}\endgraf\settowidth{\wrapboxlg}{\Large\theorem@headerfont ##1~##2\theorem@separator\normalsize\enspace}
   \vskip-1.5\baselineskip
\hangindent = \wrapboxlg\hangafter =-2\noindent
}%
{\item[\hskip\labelsep\Large\theorem@headerfont ##1~##2]
\mbox{}\endgraf\settowidth{\wrapboxlg}{\Large\theorem@headerfont ##1~##2\theorem@separator\normalsize\enspace}
   \vskip-1.5\baselineskip
\hangindent = \wrapboxlg\hangafter =-2\noindent
 {\theorem@headerfont (##3)\theorem@separator}\ }%
 \makeatother

 \theoremstyle{wrap}
 \theoremheaderfont{\upshape\bfseries}
 \theorembodyfont{\normalfont}
 \theoremseparator{.}
 \newtheorem{Ex}{Example}[section]
\usepackage{lipsum}

\begin{document}

\setcounter{section}{1}
\setcounter{Ex}{22}

\begin{Ex}
    \lipsum[11]
\end{Ex}
\bigskip

\begin{Ex}[This is the example title]
    Sed feugiat. Cum sociis natoque penatibus et magnis dis par-
    turient montes, nascetur ridiculus mus. Ut pellentesque augue
    sed urna. Vestibulum diam eros, fringilla et, consectetuer eu, nonummy id,
    sapien. Nullam at lectus. In sagittis ultrices mauris. Curabitur malesuada
    erat sit amet massa. Fusce blandit. Aliquam erat volutpat. Aliquam euismod.
    Aenean vel lectus. Nunc imperdiet justo nec dolor.
\end{Ex}

 \end{document} 

enter image description here

  • Many thanks. The only problem is that "Example 1.23" does not span two lines as I was hoping for. Do you know by any chance how I could choose \Large for "Example 1.23" and \normalsize for "this is the example title"? Although from a first look at the manual it seems that the only option are for changing the whole header, so probably now. – geo909 Mar 14 '17 at 20:52
  • I hard coded \Large in the theorem style. Please see my updated answer. What I don't understand is you say ‘Example 1.23 does not span two lines’. For me it does. Do we mean the same thing? – Bernard Mar 14 '17 at 21:47
  • Thanks, that's what I wanted. By "spanning two lines" I meant to be of the same size as two lines, but indeed this is probably not the correct definition of 'spanning' – geo909 Mar 14 '17 at 22:07
  • I still do not fully understand. Do you mean `Example 1.23’ should be laid on the second line of the surrounding text? – Bernard Mar 14 '17 at 22:16
  • I meant that the height of "Example 1.23" should be equal to the height of two lines. In any case, the result in your solution is perfect for me. – geo909 Mar 15 '17 at 3:16

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.