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

which column in multicol?

3 views
Skip to first unread message

Dirk Schlimm

unread,
Jan 1, 2010, 3:37:30 PM1/1/10
to
Hello,

is there a variable in multicol.sty which tells me in which colum a
text is currently typset?

- Dirk

Peter Flynn

unread,
Jan 2, 2010, 7:07:35 AM1/2/10
to

Unfortunately there isn't any such concept as "in which column text is
being typeset". TeX (and multicol) typesets stuff in a single galley
(column) of infinite length (for all practical purposes), and AFAIK only
breaks it into columns at the end of the multicols environment.

I guess it would be possible to add some code to that routine to create
a flag, but it would be too late by that time to do anything with it.
You'd have to test-set the text into a box which you then throw away
after having detected which column the flag would be in. This would work
for a few instances, but it might be time- or memory-consuming for large
volumes or repeated occurrences.

Or maybe this has already been done and I just haven't noticed...

///Peter

Dirk Schlimm

unread,
Jan 2, 2010, 9:11:08 AM1/2/10
to
On Jan 2, 7:07 am, Peter Flynn <peter.n...@m.silmaril.ie> wrote:

> Unfortunately there isn't any such concept as "in which column text is
> being typeset".

Thank you, Peter.

I wanted to make the behavior of certain commands (e.g., marginnote)
to be different depending on whether it is used in the left or the
right column of a 2-column environment. Apparently, that is not easy
to do automatically and I'll have to resort to doing it by hand.

Best, Dirk

Robin Fairbairns

unread,
Jan 2, 2010, 12:38:53 PM1/2/10
to
Dirk Schlimm <dsch...@gmail.com> writes:

there's a pdf primitive (\pdfsavepos, i think) that can provide a
physical page location. heiko's zref bundle has a savepos module,
that allows you to mark a position with something that looks like a
label (\zsavepos); you then retrieve the position on the next run with
\zposx and \zposy.

in principle (note the "i'm covering my back here" usage -- i've never
used the package, let alone this module) you could use this for your
automatic placement ambitions. in practice, it could be tricky, i
suppose, but it's the best i can offer.
--
Robin Fairbairns, Cambridge

Dirk Schlimm

unread,
Jan 2, 2010, 9:33:28 PM1/2/10
to
On Jan 2, 12:38 pm, r...@cl.cam.ac.uk (Robin Fairbairns) wrote:

> there's a pdf primitive (\pdfsavepos, i think) that can provide a
> physical page location.  heiko's zref bundle has a savepos module,
> that allows you to mark a position with something that looks like a
> label (\zsavepos); you then retrieve the position on the next run with
> \zposx and \zposy.
>
> in principle (note the "i'm covering my back here" usage -- i've never
> used the package, let alone this module) you could use this for your
> automatic placement ambitions.  in practice, it could be tricky, i
> suppose, but it's the best i can offer.

Thanks for the hint, Robin. At the moment I don't have time to go into
business that the experts describe as tricky, but I'll dfinitively
have a look at it when time allows.

- Dirk

Dirk Schlimm

unread,
Jan 5, 2010, 12:03:31 AM1/5/10
to
On Jan 2, 12:38 pm, r...@cl.cam.ac.uk (Robin Fairbairns) wrote:

> > there's a pdf primitive (\pdfsavepos, i think) that can provide a
> > physical page location.  heiko's zref bundle has a savepos module,
> > that allows you to mark a position with something that looks like a
> > label (\zsavepos); you then retrieve the position on the next run with
> > \zposx and \zposy.
>
> > in principle (note the "i'm covering my back here" usage -- i've never
> > used the package, let alone this module) you could use this for your
> > automatic placement ambitions.  in practice, it could be tricky, i
> > suppose, but it's the best i can offer.

I couldn't resist the temptation of at least trying to make it work in
principle and I succeeded (at least as far as I can tell). The result
is below.

Thanks Heiko for the zref package and Robin for pointing me to it.

- Dirk


\documentclass[12pt]{article}

% Sample program to have two columns in the text with margin notes on
% the left for notes belonging to the left column, and margin notes on
% the right for the right column.

% It will not work correctly, if even and odd pages have different
% margins. In this case, the value of \pivot would have to be
% recalculated for each call of \outermargin, depending on whether the
% page is even or odd.

\usepackage{geometry}
\geometry{paper=letterpaper,left=1.2in,right=1.2in,textheight=4.5in}
% Increase textheight, to change position of margin notes in example.

\usepackage{calc}
\usepackage{ifthen}
\usepackage{lipsum}
\usepackage{marginnote}
\usepackage{multicol}
\usepackage{zref-savepos}

% \pivot holds the length that is used as a threshold to determine
% whether the position is on the left of the page or on the right.
\newlength{\pivot}

% This must be called at the beginning of the text to determine the
% x-position at which the textblock begins.
\newcommand{\setpivot}{%
\setlength{\pivot}{1in}% default offset
\addtolength{\pivot}{\oddsidemargin}%
\addtolength{\pivot}{.5\textwidth}%
}

% \leftrightcol executes the first parameter if called in a left
column,
% and the second parameter if called in a right column.
\newcounter{currentpos}
\newcommand{\leftrightcol}[2]{{\zsavepos{\arabic{currentpos}}%
\ifthenelse{\lengthtest{\zposx{\arabic{currentpos}}sp<\pivot}}{#1}
{#2}%
\stepcounter{currentpos}%
}}

% \outermagin puts the marginnote on the left if called in the left
% column, and on the right if called in the right column.
\newcommand{\outermargin}[1]{\leftrightcol{\reversemarginpar\marginnote
{#1}}{\marginnote{#1}}}

\begin{document}
\setpivot

\begin{multicols}{2}
N\outermargin{NNN} \lipsum[1-1]
M\outermargin{MMM} \lipsum[2-2]
P\outermargin{OOO} \lipsum[3-3]
Q\outermargin{QQQ}
\end{multicols}

\end{document}

0 new messages