Thank you all from the beginning for your help in this. I'm completely new to LaTeX as I'm writing my bachelor thesis, so I'm sure I've made lots of mistakes...
I'm using the geometry
package because I need to modify the text width at a certain point in my thesis, and to do so I wanted to use \newgeometry
inside a custom environment.
The problem is that the part of the text that should be influenced by the new geometry runs all the way down to the next page.
I have read this
Using \restoregeometry in environment, next page runs off the page bottom
question and, as you can see, I also used the \aftergroup
comman, but still the issue persists.
My custom environment is:
\newenvironment{esempio}[1]%
{
\vspace{1.5ex}
\noindent
\underline{#1}
\nopagebreak
\newgeometry{textwidth=\textwidth}
%\leftskip=1cm
%\rightskip\leftskip
}
{
\par
\aftergroup\restoregeometry
}
And i use it like:
\begin{esempio}{$k=2$}
Il Poligono di Controllo \`e formato da $\{P_0, P_1, P_2\}$.
La curva di Bezier \`e definita come $$P_0^2(t) = (1-t)P_0^1(t) + tP_1^1(t)$$
\end{esempio}
I get the " K=2 " underlined in the correct position, but the following text is all down to the next page.
My aim would be to have an environment that lets me format a body of text like this:
bla bla bla bla bla bla bla bla bla bla bla bla
K=2
bla bla bla bla bla bla bla bla
bla bla bla bla bla bla bla bla
As a sidenote, you can see I also tried with the \leftskip
.
It gets the job done very well with the normal text, but most of the times I'll also include a picture on the side and I want the text to wrap around it, and with the \leftskip
it leaves the space on the left of the image and so the text does not wrap nicely.
@ egreg: thank you for the warm welcome and the tips :)
@ Gonzalo: thanks, your code works like a charm for the text! However, as i said in the original question, a very common situation would be to insert a figure inside that text and i'd like the text to be wrapped around the picture.
However, this causes a couple of warnings and bad boxes in the compilation process and the figure gets moved down and placed not after the "esempio" box, but after even the next paragraph, and it also creates huge blank spaces... quite weird.
Below the MWE (rettaBezier is a picture 4cmx4cm square)
\documentclass[a4paper,11pt,italian]{book}
\usepackage[italian]{babel}
\usepackage{graphicx, wrapfig, subfig}
\usepackage{changepage}
\usepackage{calc}
\usepackage{amsmath, amsthm, amssymb, mathrsfs, setspace}
\usepackage{mycommands}
\usepackage{indentfirst}
\usepackage[format=hang,font=footnotesize,labelfont=bf]{caption}
\graphicspath{{./images/}{./matlab/}}
\usepackage{lipsum}
\begin{document}
\lipsum[2]
\begin{esempio}{$k=1$}
\begin{wrapfigure}{o}[1cm]{0cm}
\centering
\includegraphics{rettaBezier}
\caption{Retta ottenuta con $P_0 = [0, 0] , P_1 = [1, 1]$}
\label{rettaBezier}
\end{wrapfigure}
\lipsum[2]
\end{esempio}
\lipsum[2]
\end{document}
\newgeometry
does its job only on whole pages. What you probably need is thequotation
environment or something similar. But this conflicts withwrapfigure
, I'm afraid.wrapfigure
.