Generalverbatim - body + margin

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
nunolf
Posts: 14
Joined: Wed Jul 18, 2007 1:41 pm

verbatim - body + margin

Post by nunolf »

Hi *

I often use the verbatim environment, and one of the coolest things, is that this env is able
to correctly put stuff across pages.

Recently, I startet working in a book (twosided) with margins.
The result I'm getting on verbatim stuff that crosses pages (and I want this to be non-float),
is:

- odd pages: outer alignement is ok
- even pages: outer alignement is not ok (does not use the margin space on the left)

How can I instruct LaTeX to correctly align the outer margin in even pages?
I know that there are tricks to do this with floats (figures and tables), by I want that this to
be non-float.

Cheers,
Nuno

P.S. I put a similar question wrongly in another forum (General:Latex Community), and till now
I did not received any reply. Thus, I put here a simpler version of my question. It was about
the listings package, which also as the ability to cross pages.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
nunolf
Posts: 14
Joined: Wed Jul 18, 2007 1:41 pm

Re: verbatim - body + margin

Post by nunolf »

Ups

Shoub be:
- odd pages: inner alignement is ok and verbatim uses the right margin if it needs
- even pages: outer alignement is not ok (does not use the margin space on the left)


Thanks
N.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

verbatim - body + margin

Post by gmedina »

In this thread you can find (part of) the answer.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
nunolf
Posts: 14
Joined: Wed Jul 18, 2007 1:41 pm

verbatim - body + margin

Post by nunolf »

Hi * & gmedina

Thanks for the reply.
Since I posted the question, I did try to solve the problem, and playing with \leftmargin and \rightmargin seems to be the path to follow.

Going to share some of my findings to help others. Here is a minimal example:

Code: Select all

\documentclass{book}

% change the page layout in the middle of a document, and robustly 
% check for typesetting on odd or even pages
\usepackage[strict]{chngpage}
% layout settings
\usepackage[a4paper,twoside,marginparwidth=60pt,marginparsep=10pt,
                  includeheadfoot]{geometry}
% source code typesetting
\usepackage{listings}

% Margin width
\newlength{\marginwidth}
\setlength{\marginwidth}{\marginparwidth}
\addtolength{\marginwidth}{\marginparsep}

\begin{document}

Here is some source code filling the body $+$ margin \ldots

\begin{adjustwidth}[]{}{-\marginwidth}
\lstinputlisting[firstnumber=1,linerange=1-13]{some.file}
\end{adjustwidth}

\end{document}
The package "chngpage" does the job of checking if the STUFF being printed is on a odd or even
page, and it takes care of changing the alignment margins of stuff inside the

Code: Select all

\begin{adjustwidth}[]{}{-\marginwidth} STUFF \end{adjustwidth}
for even and odd pages. In this case (book class) usually one wants STUFF to be expanded to outside margins, that's why the use of

Code: Select all

\begin{adjustwidth}[]{}{-\marginwidth}
. Check chngpage.sty for more info.


This only works fine if STUFF is not printed across pages. If it's the case,
then the best I found out was to break the STUFF into pieces.

I've given here an example using the listings package, did not tryed with a verbatim
environment, since the first goal was indeed to play with this listings package
(see post http://latex-community.org/viewtopic.ph ... c983f1dc35).

Many thanks.
Nuno
Post Reply