Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

It's common to set an old play (e.g. Shakespeare) with annotations on the left page and reference information on the right. I don't want to do this for a play, but I would like to set a document with annotations on one page and text on the facing page.

The catch is that I want to ensure that the annotations have parallel section spacing, because the length of the annotation may be longer or shorter than the corresponding section in the document, and I don't really want to make it so that you have to switch back and forth between documents.

That is, I would like it something like this:

+-----------------+    +-----------------+
| Heading         |    | Heading         |
| -------         |    | -------         |
| annotation      |    | this paragraph  |
|                 |    | is long         |
|                 |    |                 |
| Heading 2       |    | Heading 2       |
| ---------       |    | ---------       |
| this annotation |    | short paragraph |
| is really long  |    |                 |
+-----------------+    +-----------------+

Does anyone know of a package that can do this, or an alternate way to achieve the objective of lining up the document and annotations?

share|improve this question

3 Answers 3

up vote 10 down vote accepted

There are some packages in CTAN to have parallel texts, usually in columns. You can see the complete list in www.ctan.org/topic/parallel.

The first example using the parallel package is to have just parallel columns:

MWE

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{parallel}
\usepackage{lipsum} % dummy text
\title{Parallel columns}
\author{You}
\begin{document}
\maketitle
\begin{Parallel}{.45\textwidth}{.45\textwidth}
\ParallelLText{\section{Heading\label{h}} \lipsum[1]}
\ParallelRText{\section*{Notes to heading \ref{h}} \lipsum[2]}
\end{Parallel}
\ParallelPar
\begin{Parallel}{.45\textwidth}{.45\textwidth}
\ParallelLText{\section{Heading 2\label{h2}} \lipsum[3]}
\ParallelRText{\section*{Notes to heading \ref{h2}} \lipsum[3]}
\end{Parallel}
\end{document}

You can convert this in facing pages simply adding the option [p] in the Parallel environment (of course, modifying also the width of the columns), but the end of the environment or \ParallelPar produce a change of page (each \Parallel...Text fill a complete page). In the next example is showed the problem:

\documentclass{article}
\usepackage[margin=4cm]{geometry}
\usepackage{parallel}
\usepackage{lipsum} % dummy text
\title{Facing pages}
\author{You}
\begin{document}
\maketitle
\begin{Parallel}[p]{\textwidth}{\textwidth}
\ParallelLText{\section{Heading One   \label{h1}} \lipsum[1]}
\ParallelRText{\section*{Notes to heading \ref{h1}} \lipsum[2]}
\ParallelPar
\ParallelLText{\section{Heading One   \label{h2}} \lipsum[1]}
\ParallelRText{\section*{Notes to heading \ref{h2}} \lipsum[2]}
\end{Parallel}
\begin{Parallel}[p]{\textwidth}{\textwidth}
\ParallelLText{\section{Heading One   \label{h3}} \lipsum[1]}
\ParallelRText{\section*{Notes to heading \ref{h3}} \lipsum[2]}
\end{Parallel}
\end{document}

Edit

A completely different approach could be set manually the vertical position of each block of text in the even page with texpos package. Trial and error can be quite simplified with a macro hadling the synchrony of each pair of blocks. It must be checked that there are some separation between blocks and also that last block of each page does not extent to the lower margin, but this can be checked easily with the showboxes option and the showframes package. A example:

MWE

\documentclass[a4paper,twoside]{article}
\usepackage{afterpage}
% \usepackage{showframe} only for check block positions
\usepackage[margin=3cm]{geometry}
\usepackage{lipsum}
\usepackage{xcolor}

\usepackage{textpos} % use "showboxes" for check results
\setlength{\TPHorizModule}{.1\textwidth} % = 10% width
\setlength{\TPVertModule}{.01\textheight}% = 01% height

% Facing Double Block Macro
% Usage: 
% \FDB{position}{section}{even text}{odd text}
% position = a number between 0 to 100 (or some less)

\newcommand\FDB[4]{
\begin{textblock}{10}(0,#1)
%\textblockcolour{cyan!10} % ugly, only for testing
\section{#2\label{#2}} #3 \bigskip 
\end{textblock}
\afterpage{
\begin{textblock}{10}(0,#1)
% \textblockcolour{green!10} % ugly, only for testing
\section*{Annonations about section \ref{#2}}
 #4\bigskip
\end{textblock}}}

\title{Facing pages with 
 \texttt{texdoc} and \texttt{afterpage}}

\author{You}

\begin{document}
\maketitle
\newpage 
\FDB{0}{A title}{\lipsum[1]}{\lipsum[2]}
\FDB{25}{Another title}{\lipsum[3]}{\lipsum[4-5]}
\FDB{56}{One more title}{\lipsum[5]}{\lipsum[6]}
\FDB{78}{The last title of this page}{\lipsum[7]}{\lipsum[8]}

\newpage
% Annotations will be here 
\newpage 

\FDB{1}{The  title of a newpage}{\lipsum[9]}{\lipsum[10]}

\end{document}
share|improve this answer
    
Is there a way to do this without having to split the document like this? I'd like to be able to format the document without annotation as well, and while I guess this will allow that, it's seems far from ideal. Additionally, if one \Parallel...Text command does one page, does that mean I have to manually manipulate page breaks every time, or do you just mean that renewing the environment will cause a new page break? –  coppro Jan 12 '13 at 15:47
    
I found also very frustrating that the behaviour \ParallelPar is not like in the column format writing this answer, but I do not know how to solve it. Sorry. But if you want compile with or without long annotations and the facing pages format is not a must, may be a wide margin and the todonotes package to put margin notes do the workaround. By default make orange boxes and lines but this can be changed easily. –  Fran Jan 12 '13 at 21:33
    
Can you answer my second question? I guess I might be able to hack around the first problem with a clever set of macros built overtop \section and similar. –  coppro Jan 13 '13 at 7:28
    
I'm afraid that I do not understand the question. The example show that both \ParallelPar o renewing the environment split the pages. Moreover, this happen even deleting the six \newpage commands in a redefinition of the internal \ParallelParTwoPages! (is showed in the manual) –  Fran Jan 13 '13 at 9:58
    
Thanks. One last question: I've noticed that (in the multi-column example), sometimes the headings don't line up quite right (for instance, replace a \lipsum[2] with a single character). Do you know how to avoid this? –  coppro Jan 14 '13 at 19:19

Here's another possibility that uses the flowfram package. It calculates whether there's enough room on the page so you don't need to manually insert page breaks.

\documentclass[12pt]{scrbook}

\usepackage{flowfram}
\usepackage{lipsum}
\usepackage{etoolbox}

% set up frames

\newflowframe{\textwidth}{\textheight}{0pt}{0pt}[main]

\newdynamicframe[odd]{\textwidth}{\textheight}{0pt}{0pt}[details]
\newdynamicframe[even]{\textwidth}{\textheight}{0pt}{0pt}[annote]

% \checkisroom{idl}{text}
\makeatletter
\providecommand{\@gobblethree}[3]{}
\newsavebox\tmpsbox
\newif\ifenoughroom
\newcommand{\checkisroom}[2]{%
  \bgroup
    % get the frame's idn (stored in \ff@id)
    \@dynamicframeid{#1}%
    % temporarily suspend writing to external files
    \let\protected@write\@gobblethree
    % put the frame's contents and the pending text into 
    % the temporary sbox
    \begin{lrbox}{\tmpsbox}%
    \begin{minipage}{\textwidth}%
     \csname @dynamicframe@\romannumeral\ff@id\endcsname
     \par
     #2%
    \end{minipage}
    \end{lrbox}%
    % Does it fit the page?
    \settoheight{\@ff@tmp@y}{\usebox\tmpsbox}%
    \settodepth{\dimen@ii}{\usebox\tmpsbox}%
    \addtolength{\@ff@tmp@y}{\dimen@ii}%
    \ifdim\@ff@tmp@y>\textheight
       \global\enoughroomfalse
    \else
       \global\enoughroomtrue
    \fi
  \egroup
}

% \getcontentsheight{length}{text}
\newcommand{\getcontentsheight}[2]{%
 \bgroup
    \let\protected@write\@gobblethree
    \begin{lrbox}{\tmpsbox}%
      \begin{minipage}{\textwidth}%
       #2%
      \end{minipage}%
    \end{lrbox}%
    \settoheight{\@ff@tmp@y}{\usebox\tmpsbox}%
    \settodepth{\dimen@ii}{\usebox\tmpsbox}%
    \addtolength{\@ff@tmp@y}{\dimen@ii}%
    \global#1=\@ff@tmp@y\relax
 \egroup
}

\newcounter{heading}

% \heading{label}{title}
\newcommand{\heading}[2]{%
  \refstepcounter{heading}%
  \label{#1}%
  \markboth{#2}{#2}%
  \annote
    {%
      \section*{\ref{#1}. #2}%
    }%
    {%
      \section*{\ref{#1}. #2}%
      \addcontentsline{toc}{section}{#2}%
      \par\strut
    }%
  \afterheadingtrue
}

\newif\ifafterheading

\newlength\blockheight

\newcommand{\blocksep}{\par\vspace{2ex}}

% \annote{annotation}{text}
\newcommand{\annote}[2]{%
  \getcontentsheight{\blockheight}{#1}%
  \def\largerblock{#1}%
  \getcontentsheight{\@ff@tmp@y}{#2}%
  \ifdim\blockheight<\@ff@tmp@y
    \blockheight=\@ff@tmp@y\relax
    \def\largerblock{#2}%
  \fi
  \ifafterheading
    \edef\startblock{%
      \noexpand\blocksep
      \noexpand\begin{minipage}[t][\the\blockheight]{\the\textwidth}%
      \noexpand\setlength{\noexpand\parindent}{\the\parindent}%
      \noexpand\par\noexpand\noindent
    }%
    \afterheadingfalse
  \else
    \edef\startblock{%
      \noexpand\begin{minipage}[t][\the\blockheight]{\the\textwidth}%
      \noexpand\setlength{\noexpand\parindent}{\the\parindent}%
      \noexpand\par\noexpand\indent
    }%
  \fi
  \checkisroom{details}{\largerblock}%
  \ifenoughroom
    \@dynamicframeid{annote}%
    \expandafter\appenddynamiccontents\expandafter\ff@id
     \expandafter{%
       \expandafter\blocksep
       \startblock
       #1%
       \end{minipage}}%
    \@dynamicframeid{details}%
    \expandafter\appenddynamiccontents\expandafter\ff@id
     \expandafter{%
       \expandafter\blocksep
        \startblock
         #2%
         \end{minipage}}%
  \else
    % output 2 pages
    \cleartoeven
    \@dynamicframeid{annote}%
    \expandafter\setdynamiccontents\expandafter\ff@id
     \expandafter{\startblock#1\end{minipage}}%
    \@dynamicframeid{details}%
    \expandafter\setdynamiccontents\expandafter\ff@id
     \expandafter{\startblock#2\end{minipage}}%
  \fi
}
\makeatother

\newcommand{\cleartoeven}{%
  \ifthispageodd % KOMA command
  {\newpage}%
  {\mbox{}\newpage\mbox{}\newpage}%
}

\appto\tableofcontents{\cleartoeven}

\AtEndDocument{\cleartoeven}

\title{Sample Document}
\author{A.N. Other}

\begin{document}
\maketitle

\tableofcontents

\heading{sample}{Sample Heading}

\annote
 {Annotation on the left}
 {A longer paragraph on the right matching the annotation on the
  left.

  \lipsum[1]
 }

\heading{sample2}{Another Sample Heading}

\annote
 {\lipsum[2]}
 {\lipsum[3]}

\annote
 {Another annotation.}
 {\lipsum[4]}

\annote
 {\lipsum[5-6]}
 {\lipsum[7]}

\end{document}
share|improve this answer
    
This is very interesting answer. Thanks! I'm trying to work around your solution but I have a problem. How can I enforce a new page at the beginning of each heading (i.e. top of each page is a heading)? I tried with \cleartoeven but I failed. Moreover, Is it possible to have different text on the odd/even page header? For me on both side I have the second argument of heading on both left and right. –  Pouya Mar 11 at 19:01
    
To make it clear, I'm using your code for a work of translation where original text goes to the left and corresponding translation to the right. –  Pouya Mar 11 at 19:03
    
@Pouya It might be better to post a follow-up question linking back to this one. –  Nicola Talbot Mar 11 at 19:28
    
I added a new question as you asked. –  Pouya Mar 11 at 22:17

Here is a way whose idea is:

  1. use multicol on an A3 paper in such a way that the annotations will be on the right half and the original text on the left half

  2. then use pdfpages to alternately include each halves of each A3 page to produce an A4 document

There is however a problem that page breaks should not happen within the multicols environment. I tried to make page breaks preferably occur before a pair text+annotation, and indeed it works here in the example. But it will probably fail easily in general I guess. Or, a better way would be to put each multicols within a minipage. Some bit of testing with real-life source would be necessary here.

So we have two tex files, I called the first parallelin.tex and the second parallelout.tex. One does pdftex on the first one. Then the number of A3 pages is manually inserted in the second one (there is surely a way to automatize this). Then one runs pdftex on the second one. This produces an A4 document with a title page and then the desired layout.

\documentclass[a3paper,landscape]{article}
\usepackage[margin=4cm,foot=2cm]{geometry}
\usepackage{multicol}
\usepackage{fancyhdr} % for page numbers in the footer
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}


%% setting up the page numbers for the final document

\newcount\tmpcount
\makeatletter
\def\twicethepage{\tmpcount\c@page \multiply\tmpcount by 2 \the\tmpcount}
\def\twicethepageplusone{\tmpcount\c@page \multiply\tmpcount by 2 
               \advance\tmpcount by 1 \the\tmpcount}
\makeatother

\fancyhead{}
\fancyfoot{\hfill\hbox to 21cm{\makebox[0pt]{\twicethepage}\hss\makebox[0pt]{\twicethepageplusone}}\hfill}

\usepackage{lipsum} % dummy text

\begin{document}

%% setting up multicol
\setlength{\columnsep}{8cm} % twice the margin
\multicoltolerance\tolerance
\multicolpretolerance\pretolerance
\raggedcolumns


\begin{multicols}{2}
  \section{Heading One   \label{h1}} \lipsum[1]
\columnbreak
  \section*{Notes to heading \ref{h1}} \lipsum[10]
\end{multicols}

\pagebreak[3]
\begin{multicols}{2}
  \section{Heading Two   \label{h2}} \lipsum[2-3]
\columnbreak
  \section*{Notes to heading \ref{h2}} \lipsum[11]
\end{multicols}

\pagebreak[3]
\begin{multicols}{2}
  \section{Heading Three   \label{h3}} \lipsum[4]
\columnbreak
  \section*{Notes to heading \ref{h3}} \lipsum[12-13]
\end{multicols}

\pagebreak[3]
\begin{multicols}{2}
  \section{Heading Four   \label{h4}} \lipsum[5-6-7]
\columnbreak
  \section*{Notes to heading \ref{h4}} \lipsum[12]
\end{multicols}

\pagebreak[3]
\begin{multicols}{2}
  \section{Heading Five   \label{h5}} \lipsum[2-3]
\columnbreak
  \section*{Notes to heading \ref{h5}} \lipsum[11]
\end{multicols}

\pagebreak[3]
\begin{multicols}{2}
  \section{Heading Six   \label{h6}} \lipsum[4]
\columnbreak
  \section*{Notes to heading \ref{h6}} \lipsum[12-13]
\end{multicols}

\pagebreak[3]
\begin{multicols}{2}
  \section{Heading Seven   \label{h7}} \lipsum[5-6-7]
\columnbreak
  \section*{Notes to heading \ref{h7}} \lipsum[12]
\end{multicols}

\end{document}

Now parallelout.tex:

\documentclass[a4paper]{article}
\usepackage{pdfpages}
\begin{document}

\title{Parallel columns}
\author{Me}

\maketitle

\clearpage

\newcount\mycount
\advance\mycount1

\loop
\includepdf[noautoscale=true,offset=10.5cm 0cm,pages={\the\mycount}]{parallelin.pdf}%
\includepdf[noautoscale=true,offset=-10.5cm 0cm,pages={\the\mycount}]{parallelin.pdf}%
\ifnum\mycount<3  % <- put here the actual number of A3 pages of parallelin.pdf
\advance\mycount1
\repeat

\end{document}

I show here the output of the first step, the A3 pages:

A3 page 1

A3 page 2

A3 page 3

share|improve this answer
    
+1 for the idea of print a A3 and catch each column with pdfpages, even with 2 files, but there are problems with column owerflows. For example, a enough larger Section 3 does not make jump this section to to the next even page, but occupies the bottom of both even and odd pages, moving the notes to Section 3 to the next even page. –  Fran Jan 21 '13 at 20:10
    
@Fran yes, that's the normal behavior of multicols :-(. Have you had a look at eledpar (formerly ledpar). I did not see it mentioned on this page, perhaps for some obvious reason (I am not familiar with it, just looked briefly at the documentation). –  jfbu Jan 21 '13 at 20:20
    
@Fran besides my use of multicols can be dispensed with, it is enough to put the things in vertical boxes, side by side with a suitable horizontal separation. Of course, this is once one has renounced at solving the content accross bottom of pages problem... –  jfbu Jan 21 '13 at 20:22
    
eledpar is already mentioned in my link to CTAN, but I was unable to make even a MWE with this package (undefined \l@dpairingfalse). –  Fran Jan 21 '13 at 22:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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