I saw a book that besides its main content had the text from another book squeezed in the bottom margin. I'm wonder whether this is possible to do with LaTeX? More specifically I'm wondering whether it's possible to have two separate text and produce output such that one text goes in the main content area of the page and the other in the margin? Note that both texts may not fit on one page but needs to run over several pages.
3 Answers
A very rough approach, collecting the material for the other book in a vertical box, and using \vsplit
to split the top part of that box and put it on the left of the main text. Admittedly, the result is not good, but it might be possible to polish it.
\documentclass{article}
\textwidth=200pt\relax %??
\usepackage{xgalley,xparse}
\usepackage{lipsum}
\ExplSyntaxOn\makeatletter
\box_new:N \l_otext_tmpa_box
\box_new:N \g_otext_box
\dim_new:N \g_otext_prevdepth_dim
\skip_new:N \l_otext_sep_skip
\skip_set:Nn \l_otext_sep_skip { 20 pt }
\dim_new:N \g_otext_side_width_dim
\dim_gset:Nn \g_otext_side_width_dim { 100 pt }
\NewDocumentEnvironment{otext}{}
{
\vbox_gset:Nw \g_otext_box
\color_group_begin:
\vbox_unpack_clear:N \g_otext_box
\dim_gset_eq:NN \tex_prevdepth:D \g_otext_prevdepth_dim
\dim_set_eq:NN \l_galley_width_dim \g_otext_side_width_dim
\galley_level:
\bool_gset_false:N \g_galley_omit_next_indent_bool
\raggedleft
}
{
\color_group_end:
\dim_gset_eq:NN \g_otext_prevdepth_dim \tex_prevdepth:D
\vbox_set_end:
}
% Patch \output.
\tl_set:Nx \l_tmpa_tl { \the\output }
\tl_put_left:Nn \l_tmpa_tl
{
\vbox_set_split_to_ht:NNn \l_otext_tmpa_box \g_otext_box
{ \box_ht:N \@cclv + \box_dp:N \@cclv }
\vbox_set:Nn \@cclv
{
\hbox:n
{
\box_use_drop:N \l_otext_tmpa_box
\skip_horizontal:N \l_otext_sep_skip
\box_use_drop:N \@cclv
}
}
}
\exp_args:No \output \l_tmpa_tl
\makeatother\ExplSyntaxOff
\begin{document}
\raggedright
\begin{otext}
\section{Paragraphs 1 and 2}
\lipsum[1-2]
\end{otext}
\begin{otext}
\section{Paragraphs 3 and 4}
\lipsum[3-4]
\end{otext}
\section{Paragraphs 11 to 13}
\lipsum[11-13]
\begin{otext}
\section{Paragraphs 5 to 7}
\lipsum[5-7]
\end{otext}
\section{Paragraphs 14 to 27}
\lipsum[14-27]
\end{document}
-
Thanks for your answer. When I try to compile with pdflatex from TeX Live 2011 I get
! Missing number, treated as zero. <to be read again> ) l.54 \lipsum[1-2]
– N.N.Commented Oct 26, 2011 at 6:36 -
@N.N. Do you have the latest
xgalley
? (And the rest of expl3?) (> Oct 11, I'd say) Commented Oct 26, 2011 at 11:12 -
-
Is it possible to get LaTeX's standard justification with this?– N.N.Commented May 5, 2012 at 10:09
-
@N.N. Remove
\raggedleft
and\raggedright
, and if necessary add\sloppy
just after\begin{document}
. Commented May 6, 2012 at 9:33
You can use \marginpar
to put the second book in the margin. I prepared a sample that shows a figure, a table and some text. The sidefigure
and sidetable
environments are taken from the sidenotes package. It would be possible to put a whole book in the margin.
Two things would have to be addressed: How are the 'two books' synchronized, i.e. where are the page breaks and what happens if your first book fits on the page, but the one in the margin does not. It would even be possible to float the second book in the margin across pages, lets say for a chapter. You could use the marginfix
package for that. If you want to try that, first put the complete chapter of the second book in the margin, then put the first book. You might have to use the morefloats
package as well.
The second thing is the numbering. How are the figures and tables supposed to be numbered? Independently with a prefix, subsequently or something else?
Please change the filename in the \includegraphics
macro to try the sample.
Also, it turns out that marginfix
needs the paragraphs in the second document one at a time. So instead of \marginpar{\lipsum[1-2]}
it wants \marginpar{\lipsum[1]}\marginpar{\lipsum[2]}
.
\documentclass[]{article}
\usepackage{caption}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{morefloats}
\usepackage{marginfix}
\usepackage[paperwidth=170mm, paperheight=240mm, left=40pt, top=40pt, textwidth=220pt, marginparsep=20pt, marginparwidth=160pt, textheight=560pt, footskip=40pt]{geometry}
\makeatletter
\newsavebox{\@sidenotes@sidefigurebox}
\newenvironment{sidefigure}[1][]%
{\begin{lrbox}{\@sidenotes@sidefigurebox}%
\begin{minipage}{\marginparwidth}%
\captionsetup{type=figure}}%
{ \end{minipage}%
\end{lrbox}%
\marginpar{\usebox{\@sidenotes@sidefigurebox}}}
\newsavebox{\@sidenotes@sidetablebox}
\newenvironment{sidetable}[1][]%
{\begin{lrbox}{\@sidenotes@sidetablebox}%
\begin{minipage}{\marginparwidth}%
\captionsetup{type=table}}%
{ \end{minipage}%
\end{lrbox}%
\marginpar{\usebox{\@sidenotes@sidetablebox}}}
\makeatother
\begin{document}
%% this is document 2
\marginpar{\lipsum[4]}
\begin{sidefigure}
\includegraphics{broken_loop}
\caption{This is the caption}
\label{alabel}
\end{sidefigure}
\begin{sidetable}
\centering
% \fontfamily{ppl}\selectfont
\begin{tabular}{lllll}
\toprule
Hg&Sn&Pb&Cd&Tl \\
\midrule
0.50&0.47&0.48&0.5&0.5\\
\bottomrule
\end{tabular}
\caption{A table}
\end{sidetable}
\marginpar{\lipsum[2]}
\marginpar{\lipsum[3]}
\marginpar{\lipsum[4]}
\marginpar{\lipsum[5]}
\marginpar{\lipsum[6]}
%% this is document 1
\lipsum[1-9]
\end{document}
-
Thanks for your answer. When I put more text in document 2 it doesn't expand past page 1.– N.N.Commented Oct 26, 2011 at 6:31
-
The
marginfix
package does that trick. Then the text floats on the next page.– AndyCommented Oct 26, 2011 at 6:49 -
When I load the
marginfix
package and change\marginpar{\lipsum[4]}
to\marginpar{\lipsum[4-8]}
I get! Package marginfix Error: lost some margin notes.
– N.N.Commented Oct 26, 2011 at 6:53 -
-
I still get the same error with
morefloats
. Could you please include a working example with these additions in your answer?– N.N.Commented Oct 26, 2011 at 6:57
You may use the footnote to do this. If you squeeze an other text at the bottom of a page, you probably won't have additional footnotes as well anyhow or you could try using one of the packages that allow multiple footnotes. (Must admit I didn't try this...) Or you could use marginal notes instead. Check out this:
\documentclass{article}
\usepackage[latin]{babel}
\usepackage{blindtext}
% Don't print a footnote number:
\let\thefootnote\relax
% Reserve 40 % of a page for the squeezed contents:
\setlength{\dimen\footins}{0.4\textheight}
% Let footnotes break across pages without penalities:
\interfootnotelinepenalty=0
\begin{document}
\footnotetext{\blindtext[40]}
\Blinddocument
% If the squeezed text is longer than the main part, allow it to fill the
% entire page:
\setlength{\dimen\footins}{\textheight}
\end{document}
-
Thanks for your answer. Is it possible to let the text have their own footnotes when using this method? Also, I failed to insert a float in the second text, the one inserted as footnote.– N.N.Commented Oct 11, 2011 at 6:16
-
The main text can have notes via one of the ways pointed out above. The
bigfoot
package allows to have nested footnotes (i.e. footnotes in the "squeezed" text) if I remember correctly. But I don't think that there is a way to allow objects to float inside a footnote. Non-floating figures and tables are certainly possible. Commented Oct 11, 2011 at 22:51 -
Ok, Ideally I would like two independent texts on the same page with no restrictions either, e.g. the possibility of using floats.– N.N.Commented Oct 12, 2011 at 5:53
pdfpages
or a page-wise\includegraphics
.