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.

Similar to my last question Initial with wrapfigure -- other idea? I would like to create a wrapped environment in which I can take a \parbox or minipage environment.

The following code shows the idea solved with wrapfigure:

\newcommand{\definition}[1]{
\settowidth{\test}{#1}
\begin{wrapfigure}[3]{l}{1.2\test}
\begin{minipage}[c][3\baselineskip][c]{1.2\test}
\centering%
{}#1{}
\end{minipage}
\end{wrapfigure}\par
}

The lettrine package, which was offered by Gonzalo Medina in the answer of my above mentioned question shows an attractive solution. What I want is just a \parbox or a minipage environment at the place of the initial.

Some idea?

Edit:

After I tested the code of Ulrike I set the parbox inner position from bottom to center. The following pdf schould show my concrete idea. (And I will to apologise to be so complicated :-)) The mathematical formula schould be at the same height as the line at the right side

The red line illustrates that the baseline of the formula should be at the same heigth as the textline right to it.

The grey bars show that there should be more space to be.

That's all :)

share|improve this question
    
I think you will probably achieve better results with a description environment. Can you post a sample image of what your example should look like. Also please complete a MWE. –  Yiannis Lazarides May 6 '11 at 12:45
    
@Yiannis -- The answer of Ulrike shows what I wanted. In this "description" I like to explan the meaning of mathematical formulas like $\sigma_\text{H, lim}$ as maximal Hertzian stress; or $\int\limits_a^b f(x) dx$ as the Riemann integral. PS: what is MWE? –  Daniel May 6 '11 at 14:09
    
I am glad you have found a solution. A MWE means a minimal working example, like egreg's and Ulrike's code shown below. It saves some typing for those providing answers. –  Yiannis Lazarides May 6 '11 at 14:14

3 Answers 3

up vote 2 down vote accepted

This is a rip-off from egreg's answer, but I modified it in order to obtain the line alignment you requested. The role of the optional parameter to \begin{definition} is now something else: if present it has to be of the form number,number as in 2,3 and it then means "put 2 blank lines before and 3 after". The stuff will thus be displayed on the third line, and the indentation will cease with the seventh line. Here is an example with 2 lines before and after:

e=mc^2 as a lettrine

Update: I have edited the code so that the argument is centered with 15% space before and after. The new look is:

e=mc^2 as a centered lettrine

\documentclass{article}
\usepackage{lipsum}

\newsavebox{\defbox}
\newcount\mycount
\newtoks\strutlines

\def\numbefore #1,#2,{#1}
\def\numafter #1,#2,{#2}
\def\numtotal #1,#2,{\numexpr #1+#2+1}

\def\insertstrutlines #1{\mycount=#1\strutlines={}%
\loop\ifnum\mycount > 0 \advance\mycount by -1\relax 
\expandafter\strutlines\expandafter{\the\strutlines \strut \\} \repeat
\the\strutlines}

\newenvironment{definition}[2][1,1]{%
    \sbox\defbox{%
        \begin{tabular}[t]{@{}c@{}} 
        \insertstrutlines{\numbefore #1,} 
        \strut\smash{#2}\\ 
        \insertstrutlines{\numafter #1,}
        \end{tabular}}%
  \par\addvspace{\topsep}
  \hangindent=1.3\wd\defbox \hangafter-\numtotal #1,
  \noindent\llap{%
    \makebox[1.3\wd\defbox][c]{\smash{\usebox\defbox}}}%
  \ignorespaces}
 {\par\addvspace{\topsep}}

\begin{document}

\begin{definition}{$\displaystyle\int_0^{2s} f''(t)\mathrm{d}t$}
\lipsum[1]
\end{definition}

\begin{definition}[1,2]{$\int_0^{2s} f''(t)\mathrm{d}t = f'(2s)-f'(0)$}
\lipsum[2]
\end{definition}

\begin{definition}[2,2]{\huge $E = m c^2$}
  \lipsum[6]
\end{definition}

\end{document}
share|improve this answer
    
wow! It works really nice! And also with other size! Would you be so kind to help me about the horizontal spaces before and after the argument? (-: It would be wonderful, if the argument would be horizontaly centered with some space before and after. :) –  Daniel May 6 '11 at 18:20
    
@Daniel -- nice to know you like it. I will edit my code so that the argument will be centered: it is a matter of replacing the two occurences of l in the macro by a c. Then, there is the question whether you want the spaces before and after to be a fixed length (or another argument) or a proportional length as in egreg's code (which, I recall, is the basis of mine). In the code I edit now, I will make the space be 15% before and after. –  jfbu May 6 '11 at 19:29
    
if I understood you well, then the change of l to c should not solve the problem. I mean, I tried to change it, but it was at the left side, even if I changed l to r. I don't know where is the Problem. The space before and after should be a fix value. By a little math formula like $\sigma_\text{H,lim}$ is 15% really small. I would say 8pts on the left and the right side would be good. Take there a fix value, and then if it's small, I can change it in the code. Thanks very much! –  Daniel May 6 '11 at 19:34
    
@Daniel -- I am not sure to understand whether you understood well ;-) the macro has two instances where a positioning parameter is used: in the \begin{tabular} line and in the \makebox line. Initially, egreg had used l, and as I pointed out in my comment replacing the two l's by c's centers the argument. The current version of my answer has this replacement done. The E=mc^2 being slanted perhaps one does not perceive it to be centered, but enclose it in \mathrm to see. Suppress in the macro the two occurences of 1.3 and use \hspace{8pt}$\sigma_{\text{H,lim}}$\hspace{8pt}. –  jfbu May 6 '11 at 22:02
    
Meantime I discovered that if I set the values 1.3 before the \wd commands, it won't take any distance before and after. Then, I took a \qquad command before and after #2. In this way I can take any hspace before and after. @all, who helped: THANKS! :-) –  Daniel May 6 '11 at 22:27
\documentclass[a4paper]{article}
\newsavebox{\defbox}
\newenvironment{definition}[2][]{%
  \sbox\defbox{#1\begin{tabular}[t]{@{}l@{}}#2\end{tabular}}%
  \count255=\numexpr1+(\dimexpr(\ht\defbox+\dp\defbox))/%
    \numexpr(\baselineskip)\relax
  \par\addvspace{\topsep}
  \hangindent=1.2\wd\defbox \hangafter-\count255
  \noindent\llap{%
    \makebox[1.2\wd\defbox][l]{\smash{\usebox\defbox}}}%
  \ignorespaces}
 {\par\addvspace{\topsep}}
\usepackage{lipsum}
\begin{document}
\lipsum[2]

\begin{definition}[\bfseries]{abc\\def\\ghijklmnop}
\lipsum[1]
\end{definition}

\lipsum[2]
\end{document}

This is similar to Ulrike's solution, but automatically measures the text that must go in the "window". In the optional argument one puts declarations for the text in the "window", that's typeset in a tabular environment.

Explanation.

We reserve a box for doing measurements (\defbox); in this box we set the text to be shown in the "window" as lines of a one column left aligned tabular; before the tabular we execute possible declaration stated in the optional argument. The mandatory argument should be in a form suitable for tabular, i.e., lines separated by \\.

Next we measure the height + depth of the material and divide this length by \baselineskip; we add 1 to leave a space at the bottom: this number says how many lines must be indented.

Now we set the material: (1) we leave a space as the usual theorem-like environments do; (2) we set the hanging indent (20% more than the width of the "window") and the number of indented lines (see later); we say \noindent and put the tabular already typeset in \defbox in a zero width box (\llap) flush with the margin where we typeset the "window" after "smashing" it (so it won't contribute to the size of the line where it appears); (3) we say \ignorespaces to avoid spurious spaces, as it is necessary to do whenever an environment's start code typesets text.

At the environment's end we leave a space equal to the separation left at the beginning.

\hangindent takes as argument (not in braces) the desired indentation; \hangafter specifies when this indentation should come into action: if the number n after it is positive, the indentation will start after n lines; if the number is negative, the indentation will start at the first line and end after line number -n. It's important to remark that these two parameters are reset to zero after the next \par command (at the same group level).

share|improve this answer
    
that is a more complex and elegant Idea, but I prefer the code of Ulrike, because I don't understand the code from you :-) It uses commands, they are unknkown for me. –  Daniel May 6 '11 at 14:02
    
didn't you want to type \newenvironment{definition}[2][]{% \sbox\defbox{#1\begin{tabular}[t]{@{}l@{}}#2\end{tabular}}% because as it stands the code prints out the whole paragraph in bold and there is a funny [] at its beginning. And with the stuff as written here, the outcome is really nice looking. –  jfbu May 6 '11 at 14:18
    
@jfbu: yes, I forgot to copy a change I did only in the test file. Corrected. –  egreg May 6 '11 at 14:23
\RequirePackage{fix-cm}
\documentclass[11pt]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{lettrine}
\begin{document}
\newbox\initial
\sbox\initial{\parbox[b]{3cm}{\centering abc\\blub}}
\lettrine[lines=3, lraise=0.1, nindent=0em]%
{\usebox\initial}{ello}, here is some text without a meaning. This text
should show, how a printed text will look like at this place. If you read
this text, you will get no information. Really? Is there no
information?Hello, here is some text without a meaning. This text should
show, how a printed text will look like at this place. If you read this text,
you will get no information. Really? Is there no information?

\end{document}
share|improve this answer
    
thank's a lot. That's what I wanted, and it is easy enough to work with it, also with my basic TeX knowledge :) –  Daniel May 6 '11 at 14:03

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.