Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to stretch/decrease width of verbatim env.?

1,598 views
Skip to first unread message

twiki

unread,
Mar 9, 2009, 4:48:04 AM3/9/09
to
I've this environment:

\begin{verbatim}
--------------------------------------
bla bla bla
--------------------------------------
\end{verbatim}

I want that the width of this environment is equal to \textwidth

Suggestions?

--
THANX!

Lars Madsen

unread,
Mar 9, 2009, 5:14:46 AM3/9/09
to

how? the width of each character is a fixed size, so I suggest you
explain in a bit more detail what exactly it is you want


--

/daleif (remove RTFSIGNATURE from email address)

LaTeX FAQ: http://www.tex.ac.uk/faq
LaTeX book: http://www.imf.au.dk/system/latex/bog/ (in Danish)
Remember to post minimal examples, see URL below
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=minxampl
http://www.minimalbeispiel.de/mini-en.html

twiki

unread,
Mar 9, 2009, 5:49:36 AM3/9/09
to
>
> how? the width of each character is a fixed size, so I suggest you
> explain in a bit more detail what exactly it is you want
>

...not the width of *each* character... but the width of the *total box*
which
contain the environment.

I use verbatim env. because the fixed size is desired but
the width of the environment exceeds the right-margin
(example the verbatim code for a shell-script).

I want to *shrink* the box of the environment exactly to textwidth.

Rolf Niepraschk

unread,
Mar 9, 2009, 5:53:22 AM3/9/09
to
twiki schrieb:
...

>
> I want to *shrink* the box of the environment exactly to textwidth.
>

Look at the listings package ("language={}"). It is more flexible.

...Rolf

twiki

unread,
Mar 9, 2009, 6:08:57 AM3/9/09
to
>
> Look at the listings package ("language={}"). It is more flexible.

...well, but i don't want to edit programs or scripts. I want
simply write some block in plain-text without to count the
spaces for each line!

I want only the *same width* (textwidth) for env1 and env2:

\begin{verbatim} %env1 (too large)
-------------------------------
here and here
-------------------------------
\end{verbatim}


\begin{verbatim} %env2 (too strict)
----------------------
here here
----------------------
\end{verbatim}

Ulrike Fischer

unread,
Mar 9, 2009, 6:11:10 AM3/9/09
to

But how do you want to shrink? Do you want to scale down the whole
box? This will lead to different font size on the page and will look
awful.

Either break your lines manually or use the listings package. It has
an option for line breaks.


--
Ulrike Fischer

Lars Madsen

unread,
Mar 9, 2009, 6:15:13 AM3/9/09
to

then you will have to save the contents in a box and then scale that box
using e.g. \resizebox, but as Rolf already mentioned I'd reather
recommend using the listings package, it is highly configurable, it can
even break long lines.

I think it will look odd if you through out your document have code
listings in various different font sizes

Rolf Niepraschk

unread,
Mar 9, 2009, 6:18:34 AM3/9/09
to
twiki schrieb:

>>
>> Look at the listings package ("language={}"). It is more flexible.
>
> ...well, but i don't want to edit programs or scripts. I want
> simply write some block in plain-text without to count the
> spaces for each line!

I can't understand why you must count anything. You can give the listing
environment a width like you want. In addition you can frame these
constant-with boxes an much more. See the documentation!

...Rolf

twiki

unread,
Mar 9, 2009, 6:32:11 AM3/9/09
to

...ok, but how to use resizebox with verbatim?

\resizebox{\textwidth}{}{\begin{verbatim}
bla bla
\end{verbatim}}

Lars Madsen

unread,
Mar 9, 2009, 6:45:16 AM3/9/09
to

no, verbatim is a special beast, it can only be used inside other
environments, so you first have to store the contents inside a box

\newsavebox\mybox

\begin{lrbox}{\mybox}
\begin{verbatim}
...
\end{verbatim}
\end{lrbox}

\resizebox{\textwidth}{}{\usebox{\mybox}}

(untested)

but as lots of people have now told you, please reconsider this and use
a better construction. Another benefit of using listings is that it has
syntax highlighting and is able to get the source kode form external files.

twiki

unread,
Mar 9, 2009, 6:53:14 AM3/9/09
to
>
> \newsavebox\mybox
>
> \begin{lrbox}{\mybox}
> \begin{verbatim}
> ...
> \end{verbatim}
> \end{lrbox}
>
> \resizebox{\textwidth}{}{\usebox{\mybox}}
>
> (untested)

-----> LaTeX Error: Something's wrong--perhaps a missing \item.

>
> but as lots of people have now told you, please reconsider this and use
> a better construction. Another benefit of using listings is that it has
> syntax highlighting and is able to get the source kode form external
> files.
>

...ok, but i want simply to shrink the text/tables/notes in plain text
and not to edit code.

Lars Madsen

unread,
Mar 9, 2009, 7:00:44 AM3/9/09
to
twiki wrote:
>>
>> \newsavebox\mybox
>>
>> \begin{lrbox}{\mybox}
>> \begin{verbatim}
>> ...
>> \end{verbatim}
>> \end{lrbox}
>>
>> \resizebox{\textwidth}{}{\usebox{\mybox}}
>>
>> (untested)
>
> -----> LaTeX Error: Something's wrong--perhaps a missing \item.
>

then perhaps verbatim cannot be used like this, as I said verbatim is a
special beast

>>
>> but as lots of people have now told you, please reconsider this and
>> use a better construction. Another benefit of using listings is that
>> it has syntax highlighting and is able to get the source kode form
>> external files.
>>
>
> ...ok, but i want simply to shrink the text/tables/notes in plain text
> and not to edit code.

which code? the code you want to display our the source of your document

twiki

unread,
Mar 9, 2009, 7:30:12 AM3/9/09
to
> which code? the code you want to display our the source of your document
>

* example 1 (plain-text tables)

\begin{verbatim}
---------------------------------------------
First date 10/5 - 11/8 - 23/9
---------------------------------------------
[notes on
10/5]
---------------------------------------------
\end{verbatim}


* example 2 (your long-line post without wrapping...)


\begin{verbatim}


no, verbatim is a special beast, it can only be used inside other
environments, so you first have
to store the contents inside a box

\newsavebox\mybox

\begin{lrbox}{\mybox}
\begin{verbatim}
...
\end{verbatim}
\end{lrbox}

\resizebox{\textwidth}{}{\usebox{\mybox}}

(untested)

but as lots of people have now told you, please reconsider this and use

a better construction.
Another benefit of using listings is that it has syntax highlighting
and is able to get the source
kode form external files.

\end{verbatim}


* example 3 (copy-and-paste preformatted text from web)

\begin{verbatim}
I've paid my dues / Time after time
I've done my sentence / But committed no crime
And bad mistakes / Ive made a few / I've had my share of sand kicked in
my face ---> TOO LONG
But I've come through...

\end{verbatim}

Ulrike Fischer

unread,
Mar 9, 2009, 7:34:10 AM3/9/09
to
Am Mon, 09 Mar 2009 11:45:16 +0100 schrieb Lars Madsen:


>> ...ok, but how to use resizebox with verbatim?
>>
>> \resizebox{\textwidth}{}{\begin{verbatim}
>> bla bla
>> \end{verbatim}}
>
> no, verbatim is a special beast, it can only be used inside other
> environments, so you first have to store the contents inside a box
>
> \newsavebox\mybox
>
> \begin{lrbox}{\mybox}
> \begin{verbatim}
> ...
> \end{verbatim}
> \end{lrbox}
>
> \resizebox{\textwidth}{}{\usebox{\mybox}}
>
> (untested)

There is a ! missing in \resizebox, and you will have to put a box
around the verbatim.

\documentclass[a4paper,twoside]{book}
\usepackage{varwidth}
\usepackage{graphicx}

\begin{document}
\newsavebox\mybox

\begin{lrbox}{\mybox}
\begin{varwidth}{3\textwidth}


\begin{verbatim}
...
\end{verbatim}

\end{varwidth}
\end{lrbox}

\resizebox{\textwidth}{!}{\usebox{\mybox}}
\end{document}

--
Ulrike Fischer

Ulrike Fischer

unread,
Mar 9, 2009, 7:42:00 AM3/9/09
to
Am Mon, 09 Mar 2009 12:30:12 +0100 schrieb twiki:

> * example 3 (copy-and-paste preformatted text from web)
>
> \begin{verbatim}
> I've paid my dues / Time after time
> I've done my sentence / But committed no crime
> And bad mistakes / Ive made a few / I've had my share of sand kicked in
> my face ---> TOO LONG
> But I've come through...
>
> \end{verbatim}

\begingroup\ttfamily\obeylines

I've paid my dues / Time after time
I've done my sentence / But committed no crime
And bad mistakes / Ive made a few / I've had my share of sand
kicked in
my face ---> TOO LONG
But I've come through...

\endgroup


--
Ulrike Fischer

twiki

unread,
Mar 9, 2009, 11:08:16 AM3/9/09
to
I am not enough *intelligible*... my question is
how to reduce the BOX with verbatim content in order
to it fit in a document.


\textwidth
^ ^
|-------------|

This is normal
formatted text
with LaTeX.
.-------------.
| |
| | <----- This is verbatim BOX stretched to fit!
| |
`-------------'
This is yet
formatted text
with LaTeX.


I don't want to insert auto-break in my lines.

Example:

.-----------------------------.
| Cm Gm7/C |


| I ve paid my dues |

| Cm Gm7/C |
| And time after time |
| Cm Gm7/C | <---- Verbatim *without*
| I ve done my sentence | breaks is indispensable
| Cm Gm7/C |
| But commited no crime |
| |
`-----------------------------'
^
|
I want to shrink/stretch this BOX and not insert braks.

Ulrike Fischer

unread,
Mar 9, 2009, 11:26:55 AM3/9/09
to
Am Mon, 09 Mar 2009 16:08:16 +0100 schrieb twiki:

> I am not enough *intelligible*... my question is
> how to reduce the BOX with verbatim content in order
> to it fit in a document.

And what's wrong with the code with \resizebox and varwidth I sent
four hours ago?

--
Ulrike Fischer

twiki

unread,
Mar 9, 2009, 1:36:32 PM3/9/09
to
>> to it fit in a document.
>
> And what's wrong with the code with \resizebox and varwidth I sent
> four hours ago?
>

...ops! Pardon, i try your code only now...
It's exatly that i want!

Thanx!

0 new messages