4

I sometimes have bits of text I want to emphasize. My idea is to change the margin with changepage's adjustwidth and then frame the text with \fbox. The problem is this prevents linebreaks. For now, the only solution I have is to put \vbox inside \fbox and split the text into \hboxes by copying the automatic line division and hyphenation carried out without \fbox. This also implies having to stretch some \hboxes, therefore calculating the opportune width for those. Is there a better way to do this? The idea is:

enter image description here

typeset by:

metodi numerici sui problemi di Cauchy, dà una definizione che è tutto fuorché matematica, nel senso che dà una definizione di questo tipo:
\begin{adjustwidth}{1cm}{1cm}
\dimen1=\linewidth
\advance\dimen1 by -0.3cm
\fbox{\itshape\vbox{\just[\dimen1]{Se un problema con una regione di stabilità finita in un intervallo di tem-} \just[\dimen1]{po per ogni condizione iniziale è forzato ad usare un passo di integrazione} \just[\dimen1]{troppo piccolo rispetto alla regolarità della soluzione il problema è stiff in} \hbox{quell'intervallo.}}}
\end{adjustwidth}
Tipicamente vado a scegliere i metodi con una regione di assoluta stabilità infinita, e tipicamente quelli che permettono con facilità di cambiare il passo di integrazione. Ovviamente

Note: \just is defined as:

\newcommand{\just}[2][\linewidth]{\hbox to #1{#2}}

Edit: I'm probably using all those \hboxes to avoid this:

enter image description here

Apart from the indent, which can be suppressed by \noindent, why does the text extend not only beyond the margin of adjustwidth but also beyond that of the text outside it? Is it because \textwidth is set back to normal and needs to be altered? Note that altering \linewidth changes nothing.

egreg
  • 1,121,712
MickG
  • 5,426
  • 1
    Why not a centered minipage or even better tcolorbox? – percusse Sep 18 '14 at 14:12
  • I'm afraid I basically know neither :). I haven't even ever heard of the latter. – MickG Sep 18 '14 at 14:13
  • The construction seems similar to a single-cell tabular where you could use a p{<len>}-column. Then the content will wrap all day long... – Werner Sep 18 '14 at 14:16
  • don't use \vbox in latex documents, it is a tex primitive so can be used in code with care but not taking top level document text like this, but even if you did you \vbox why the \hbox which just stops line breaking? why not just put the text into the \vbox and let tex break it into lines? – David Carlisle Sep 18 '14 at 14:18
  • @DavidCarlisle please see the edit. – MickG Sep 18 '14 at 14:30
  • 1
    \vbox just starts a new vertical list it doesn't reset parameters to be suitable for typesetting in that new context. minipage is \vbox but sets \hsize and \parindent and several other things, and works correctly with colour. – David Carlisle Sep 18 '14 at 14:38

2 Answers2

5

It seems you want

metodi numerici sui problemi di Cauchy, 
dà una definizione che è tutto fuorché matematica, 
nel senso che dà una definizione di questo tipo:
\begin{center}
\fbox{\begin{minipage}{\dimexpr\textwidth-2cm}
\itshape
 Se un problema con una regione di stabilità 
 finita in un intervallo di tempo per ogni 
 condizione iniziale è forzato ad usare un passo
 di integrazione troppo piccolo rispetto alla regolarità 
della soluzione il problema è stiff in quell'intervallo.
\end{minipage}}
\end{center}
David Carlisle
  • 757,742
  • Yep, that also adds vertical space above and below. Perfect. – MickG Sep 18 '14 at 14:26
  • Is there any reason to use minipage rather than \parbox? I only ask because I tend to use the latter rather than the former and would like to know if I ought not do so. – cfr Sep 18 '14 at 22:12
  • 1
    @cfr minipage is essentially an environment form of parbox (they mostly use the same code internally) but like most environments it has the advantage that verb/verbatim can be used (but not here because of the fbox) minipage resets a few more "page" oriented things and allows footnotes within the "minipage" which is either good or bad depending on which you want – David Carlisle Sep 18 '14 at 22:28
  • Thanks. So \parbox is not bad when it works? I tend to use \parbox in these sorts of cases when it works and minipage when \parbox doesn't. I take it from your answer I'm not doing anything too awful. – cfr Sep 18 '14 at 22:40
  • 1
    @cfr as I say if you're not using footnotes or verb, there's not much difference (slightly different behaviour of white space at the top where minipage tries harder to be like a page and drop space) tabular p column is more or less same as parbox of course as well. – David Carlisle Sep 18 '14 at 22:44
3

This is similar to David's answer, setting the quote inside a tabular using a fixed-width p-column. The optional parameter to centerquote is used to indicate the text block adjustment:

enter image description here

\documentclass{article}
\usepackage[margin=1in]{geometry}% Just for this example
\usepackage{lipsum}
\newenvironment{centerquote}[1][1cm]
 {\begin{center}
  \begin{tabular}{|p{\dimexpr\linewidth-#1-#1}|}
  \hline}
 {\\ \hline
  \end{tabular}
  \end{center}}
\begin{document}
\lipsum[1]

\begin{centerquote}
  \lipsum*[2]
\end{centerquote}

\lipsum[3]

\begin{centerquote}[2cm]
  \lipsum*[4]
\end{centerquote}

\lipsum[5]
\end{document}
Werner
  • 603,163