3

What I want

I have a document that includes text from several external .tex files. These files can contain \section{} commands or \begin{quote} environments. Furthermore, I use the lineno package to number the lines of the includes files. To allow writing notes to the printing documents, I would like to limit the width of the included text. This width, however, should only affect the included text and not other parts of the document.

Code example

Basically, my code should look like this:

\chapter{Entry number 10}
Text text text text text text text text text text text text text

% HELP ME: command to set text width

\linenumbers
\input{external.tex}
\nolinenumbers

% HELP ME: command to reset text width

How the result should look like

ENTRY NUMBER 10
===============

Text text text text text text text text text text text text text

1. Included part 10-a
---------------------

2. Text of the included part that has
3. a smaller text width that even works
4. when quotations or other subsections
5. are used.

6. Note the line numbers.

Minimal Example

Here is an example to demonstrate what I want and what does not work:

\documentclass{article}
\usepackage{lineno}
\usepackage{lipsum}

\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% imagine this part is included from a file %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% show line numbers
\linenumbers

% HELPME: something that does not correctly work
\par\begingroup\rightskip12em

% a paragraph with correct margin
\section{This is an example for a very long subtitle}
\lipsum[1]

% margin is ignored for quoted text
\begin{quote}
\lipsum[1]
\end{quote}

% margin is ignored for item lists
\begin{itemize}
\item \lipsum[1]
\end{itemize} 

\par\endgroup

% no line numbers beyond this
\nolinenumbers
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}

Note that text in the quote environment and the list does not have a correct margin.

What I tried

  • minipage: Works perfectly, but does not work if the included document is longer than one page. A minipage environment that floats over many pages would help
  • \newgeometry{} command of the geometry package: Works perfectly, but always begins a whole new page. I, however, want the change to only affect the included part and not the surrounding text.
  • Using adjustwidth environment from the changepage package: This does not work when the text in the environment contains \section{} commands.
  • Using an environment and change its width: Had several issues... For instance, the margin was ignored as soon as the included text contained a quote. Other environment could not cope with \section{} commands in the included text.

Another problem

\documentclass{report}

\usepackage{changepage}

\begin{document}

\chapter{Text1}

\begin{adjustwidth}{1cm}{2cm}

\section{Text2}

Text3

\begin{quote}
Text4
\end{quote}

\end{adjustwidth}

\end{document}

The reason why I did not use adjustwidth before was that the above example has a compilation error: "Something's wrong--perhaps a missing \item." in the line of \begin{quote}. The error disappears when I remove either of

  • the line \chapter{Text1}
  • the line \section{Text2}
  • the line Text3
  • the adjustwidth environment

How can this be?

Edit: I asked a new question (Strange compilation problem using adjustwidth environment from changepage package) and close this one.

3

As linked in the comments the environment works as expected

\documentclass{article}
\usepackage{lineno}
\usepackage{lipsum}
\usepackage{showframe}
\usepackage{changepage}
\begin{document}
\begin{adjustwidth}{1cm}{2cm}
\linenumbers
\section{This is an example for a very long subtitle}
\lipsum[1]
\begin{quote}
\lipsum[1]
\end{quote}
\begin{itemize}
\item \lipsum[1]
\end{itemize} 
\end{adjustwidth}
\end{document}

enter image description here

  • Marco, Thanks a lot! The example works. It does, however, not work in my setting. I describe the problem above. It would be so cool if you had another look at this. – Niels Lohmann Jun 23 '12 at 12:44
  • I explained the problem arising with adjustwidth above under "Another problem". It brings me a strange compilation error. – Niels Lohmann Jun 23 '12 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.