5

I have a question about aligning text in two columns. A similar question was asked here:Two Columns whose content is positioned relative to each other, but I wasn't able to get the example solution working to see if it would solve my problem. I am pretty new to LaTeX, otherwise I would try to write out some code to work it out myself.

Here is some text that needs to be
in one column[1]. And sometimes        1. A column is a body of text that
it needs to keep going while some      is arranged up and down. A column 
                                       might also refer the tall pillars
                                       in a Greek or Roman style building.
words are highlighted[2] on the        2. Highlighting is the process of
other side but things over here        bringing a reader's attention to
might need to just keep trucking       a particular point.
along.
     No time to stop and smell the
roses or take the road less trav-
eled. The most important[3] thing      3. What is important is relative.
is that the information that is        what some people consider critical,
                                       others consider peripheral.
highlighted is on the same line        4. Same --- similar or sharing a
as the beginning of the comment        great number of qualities
about it.

The result does not need the number indicators on in the left column, they are simply there to help illustrate which word the text on the right needs to be aligned with. Here is an image of what I am trying to accomplish: Desired Output (ACT English Section)

here is a minimal working example, I think:

\documentclass{book}
\usepackage{amsmath,soul}
\usepackage{parcolumns}
\usepackage{soulpos}
\ulposdef{\ulnumaux}{%
   $\underset{\saveulnum}{\rule[-.7ex]{\ulwidth}{.4pt}}$}
\newcommand{\ulnum}[2]{%
  \def\saveulnum{#1}%
  \ulnumaux{#2}}
\begin{document}
\begin{parcolumns}{2}
\colchunk[1]{Here is a \ulnum{1}{block} of text that might end up being kind of long. It is usually on a \ulnum{2}{random topic}, though sometimes it is interesting. What is important is that certain sections need to be aligned with one another, and sometimes this might cause things to collide.}
\colchunk[2]{
\begin{enumerate}
\item A block is single continuous body, sometimes composed of smaller parts.
\item like golf, the art of the Renaissance, amoebas, or the Allegory of the Cave
\end{enumerate}
}
\end{parcolumns}
\begin{parcolumns}{2}
\colchunk[1]{While in this example things are in \ulnum{3}{parallel} paragraphs, I would like the numbers on the right to be able to align with the underlined sections on the left. \ulnum{4}{That means in each column, there will be} a lot of blank space in \ulnum{5}{sections} where underlined sections are close together.\fbox{6}}
\colchunk[2]{
\begin{enumerate}
\setcounter{enumi}{2}
\item Here these paragraphs are nicely spaced side by side, but I don't need the text in column 2 to get affected by spacing in column 2, except that the top line of the comment should line line up with it's underlined section
\item Maybe
\item or other parts of the text where column 2 is longer than the space between it and the next number in column 1.
\item Sometimes I might want to align text with a box too, though if there are two numbers on a line, it is ok for the text associated with them to be stacked in the other column, but this will mean a lot of space over there
\end{enumerate}}
\end{parcolumns}
\end{document}

And its output: Output from MWE Thanks

Using the input from the comment below I was able to produce much higher quality output. I am having a problem with using it on two pages. here is a reproducible version. When I get to the second page, it puts the \columnnote all the way at the bottom of the page.

\documentclass{article}
\usepackage{amsmath,soul}
\usepackage{paracol}
\usepackage{geometry}
\usepackage{soulpos}
\usepackage{tikzpagenodes}
\usetikzlibrary{intersections}
\pagestyle{empty}
\ulposdef{\ulnumaux}{%
   $\underset{\saveulnum}{\rule[-.7ex]{\ulwidth}{.4pt}}$}
\newcommand{\ulnum}[2]{%
  \def\saveulnum{#1}%
  \ulnumaux{#2}}

\newcounter{pagecheck}
\newlength{\tempa}
\newlength{\tempb}

\newcommand*{\myitem}[2]% #1=number or \thecounter, #2=text
{\noindent\makebox[\labelwidth][r]{{#1}.}\hspace{\labelsep}%
\setlength{\tempa}{\linewidth}%
\addtolength{\tempa}{-\labelwidth}%
\addtolength{\tempa}{-\labelsep}%
\parbox[t]{\tempa}{#2}}

\makeatletter
\newcommand{\checkpage}%
{\ifnum\c@page>\c@pagecheck
\c@pagecheck=\c@page%
\tikz[remember picture,overlay]{\coordinate (last) at (current page column 2 area.north west);}
\fi}
\makeatother

\newcommand{\columnnote}[2][1]% #1=estimated number of lines overlap (optional), #2=text of note)
{\checkpage% reset to top of column 2 at new page
\begin{tikzpicture}[remember picture,overlay]
\coordinate (here) at (0pt,.6\baselineskip);
\pgfextracty{\tempa}{\pgfpointanchor{here}{center}}
\pgfextracty{\tempb}{\pgfpointanchor{last}{center}}
\ifdim\tempa<\tempb{\coordinate (last) at (last |- here);}\fi
\node[below right, inner sep=0pt] (note) at (last) {\parbox{\linewidth}{#2}};
\coordinate[below=\baselineskip] (last) at (note.south west);
\end{tikzpicture}%
\settoheight{\tempa}{\parbox[c]{\linewidth}{#2}}%
\setlength{\tempa}{2\tempa}% full height
\setlength{\tempb}{#1\baselineskip}%
\ifdim\tempa>\tempb\addtolength{\tempa}{-\tempb}%
\vspace{\tempa}\fi}

\begin{document}
\begin{paracol}{2}
Here in the United States of America, we celebrate the \ulnum{1}{4th of July because it is a day}\columnnote[2.1]{\myitem{1}{
\begin{description}
\vspace{-3.75 ex}
\item[A] NO CHANGE
\item[B] 4th of July, the day
\item[C] 4th of July which is the day
\item[D] 4th of July, and is 
\end{description}
}}
 dedicated to the spirit of independence that inspired early British Colonists to \ulnum{2}{wage war}\columnnote[2]{\myitem{2}{
 Which of the following alternatives for the underlined portion would NOT be acceptable?
 \begin{description}
 \item[F] start a revolution
 \item[G] revolt
 \item[H] wage a strategic war
 \item[J] to the waging war
 \end{description}
 }} against their overseas masters. If you look back on the history of that \ulnum{3}{day, however, it}\columnnote[2.1]{\myitem{3}{
\begin{description}
\vspace{-3.75 ex}
\item[A] NO CHANGE
\item[B] day, however it
\item[C] day, because it
\item[D] day. It
\end{description}
}}
 celebrates the ratification of the Declaration of Independence. While this is an important milestone in establishing one of the first modern democracies, it is not as dramatic as the days celebrated by some other countries. \fbox{4}\columnnote[6]{\vspace{-6ex}\myitem{4}{
 At this point the writer is considering adding the following sentence --- \emph{`The fireworks on Independence Day and the Star Spangled Banner are more reminiscent of a revolutionary-war spirit than simply signing a document.'} --- should the writer make this addition here?
 \begin{description}
 \item[F] Yes, it is relevant to the focus of the paragraph, which is Independence Day
 \item[G] Yes, it helps the reader get in the spirit of Independence Day
 \item[H] No, it is distracting from the focus of this paragraph, which is the historical events that took place on July 4th, 1776
 \item[J] No, this information does not belong in this essay
 \end{description}
}}

Take for example the French `Bastille Day.' \ulnum{5}{This was a day that} \columnnote[100]{\myitem{5}{
\begin{description}
\vspace{-3.75 ex}
\item[A] NO CHANGE
\item[B] This awesome day
\item[C] They decided to make a day that
\item[D] It
\end{description}
}}
commemorates the storming of a royal fortress in the early days of the French Revolution.
\end{paracol}
\end{document}
  • 2
    Welcome to TeX.SE. It would be helpful if you took the code in the linked question and added your own text to yield a fully compilable MWE including \documentclass and the appropriate packages that illustrates the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem, instead of spending time to first reproduce the problem. – Peter Grill Aug 6 '14 at 16:13
  • Thanks for the update. Can you also provide details (preferably by an image) of what the desired output is. Since the inter line spacing is being interrupted by the soul package, there are spaces on the right side so that the text lines are properly aligned. Is that what the problem is? – Peter Grill Aug 6 '14 at 19:11
  • I'd like it to look like the example I posted above my MWE. The only real relationship between the two columns should be that the paragraphs on the right need to start on the same line as a particular word (or group of words) on the left. Both Columns should have have big blank spaces to to fix this. Right now the 1. on the right is below the 1, on the left. Of the numbers in the provided example, only [3] is correctly aligned right now. – Zool Aug 6 '14 at 19:54
  • Check out the paracol package. See tex.stackexchange.com/questions/137283/… – John Kormylo Aug 6 '14 at 20:26
  • I just tried the paracol package. I'd like to be able to use something like \marginalnote but have it put the content in the other column, rather than the margin. Any idea how I can make that work? Also, That doesn't seem to help the problem of adding empty lines in the main body text to account for when the right column gets crowded. using paracol, badly – Zool Aug 6 '14 at 21:36
3

This solution never actually uses the second column, but it still needs paracol or parcolumn to leave the second column blank. You could create a single left column using geometry, but this is simpler.

The key here is the estimated number of lines overlapped. There is no way to accurately compute this value while the paragraph is still under construction. The smaller the number, the bigger the gap at the end of the line.

It should be noted that when \vspace is used in the middle of a line, it is not implemented until the start of the next line, so the gap will always appear after the line containing \columnnote.

Lastly, it generally takes two runs to get a good page. This is due to the fact that tikz uses the aux file to store location information.

\documentclass{article}
\usepackage{amsmath,soul}
\usepackage{paracol}
\usepackage{geometry}
\usepackage{soulpos}
\usepackage{tikzpagenodes}
\usetikzlibrary{intersections}

\pagestyle{empty}
\ulposdef{\ulnumaux}{%
   $\underset{\saveulnum}{\rule[-.7ex]{\ulwidth}{.4pt}}$}
\newcommand{\ulnum}[2]{%
  \def\saveulnum{#1}%
  \ulnumaux{#2}}

\makeatletter
\let\tikzpage=\oddpage@page
\makeatother

\newcounter{pagetest}
\newlength{\tempa}
\newlength{\tempb}
\newlength{\tempc}

\newcommand*{\myitem}[2]% #1=number or \thecounter, #2=text
{\begingroup%
\noindent\makebox[\labelwidth][r]{{#1}.}\hspace{\labelsep}%
\advance \linewidth by -\labelwidth
\advance \linewidth by -\labelsep
\parbox[t]{\linewidth}{#2}%
\endgroup}

\newcommand*{\columnnote}[2][100]% #1=estimated number of lines overlap (optional), #2=text of note)
{\settoheight{\tempa}{\parbox[c]{\linewidth}{#2}}%
\setlength{\tempa}{2\tempa}% full height needed
\begin{tikzpicture}[remember picture,overlay]
\ifnum\value{pagetest}=\tikzpage\relax% reset to top of column 2
\else{\coordinate (last) at (current page column 2 area.north west);}
\setcounter{pagetest}{\tikzpage}\fi
\coordinate (here) at (0pt,.6\baselineskip);
\coordinate[above=\tempa] (remaining) at (current page column 2 area.south west);
\pgfextracty{\tempb}{\pgfpointanchor{last}{center}}
\pgfextracty{\tempc}{\pgfpointanchor{remaining}{center}}
\ifdim\tempb<\tempc{\coordinate (remaining) at (last);}% use as much space as you have
\setlength{\tempc}{\tempb}\fi
\pgfextracty{\tempb}{\pgfpointanchor{here}{center}}
\ifdim\tempb<\tempc{\coordinate (last) at (remaining);}% use as much space as you need
\else
\pgfextracty{\tempc}{\pgfpointanchor{last}{center}}
\ifdim\tempb<\tempc\coordinate (last) at (last |- here);\fi% align text
\fi
\node[below right, inner sep=0pt] (note) at (last) {\parbox{\linewidth}{#2}};
\coordinate[below=\baselineskip] (last) at (note.south west);
\end{tikzpicture}%
\setlength{\tempb}{#1\baselineskip}% insert gap in left column
\ifdim\tempa>\tempb\addtolength{\tempa}{-\tempb}%
\vspace{\tempa}\fi}

\begin{document}
\begin{paracol}{2}
Here in the United States of America, we celebrate the \ulnum{1}{4th of July because it is a day}\columnnote[2.1]{\myitem{1}{
\begin{description}
\vspace{-3.75 ex}
\item[A] NO CHANGE
\item[B] 4th of July, the day
\item[C] 4th of July which is the day
\item[D] 4th of July, and is 
\end{description}
}}
 dedicated to the spirit of independence that inspired early British Colonists to \ulnum{2}{wage war}\columnnote[2]{\myitem{2}{
 Which of the following alternatives for the underlined portion would NOT be acceptable?
 \begin{description}
 \item[F] start a revolution
 \item[G] revolt
 \item[H] wage a strategic war
 \item[J] to the waging war
 \end{description}
 }} against their overseas masters. If you look back on the history of that \ulnum{3}{day, however, it}\columnnote[2.1]{\myitem{3}{
\begin{description}
\vspace{-3.75 ex}
\item[A] NO CHANGE
\item[B] day, however it
\item[C] day, because it
\item[D] day. It
\end{description}
}}
 celebrates the ratification of the Declaration of Independence. While this is an important milestone in establishing one of the first modern democracies, it is not as dramatic as the days celebrated by some other countries. \fbox{4}\columnnote[6]{\myitem{4}{
At this point the writer is considering adding the following sentence --- \emph{`The fireworks on Independence Day and the Star Spangled Banner are more reminiscent of a revolutionary-war spirit than simply signing a document.'} --- should the writer make this addition here?
 \begin{description}
 \item[F] Yes, it is relevant to the focus of the paragraph, which is Independence Day
 \item[G] Yes, it helps the reader get in the spirit of Independence Day
 \item[H] No, it is distracting from the focus of this paragraph, which is the historical events that took place on July 4th, 1776
 \item[J] No, this information does not belong in this essay
 \end{description}}}

Take for example the French `Bastille Day.' \ulnum{5}{This was a day that}\columnnote{\myitem{5}{
\begin{description}
\vspace{-3.75 ex}
\item[A] NO CHANGE
\item[B] This awesome day
\item[C] They decided to make a day that
\item[D] It
\end{description}
}}
commemorates the storming of a royal fortress in the early days of the French Revolution.
\end{paracol}
\end{document}

page 1


page 2

  • Wow! Thank you alot. This is almost perfect for my purposes. I have two comments: 1) the text between \columnnote calls should belong to the text above it, not below (if possible), and 2) Is there a way to allow the \myitem to allow a description list without an extra line for an item before the list? (see #20 and 23 in the example image above if you wonder what I think it should look like). – Zool Aug 8 '14 at 22:39
  • @Zool - It should be possible to add space above the line using \rule. All \myitem does is set up hanging indentation using a \parbox. You can use \newlines and \vspace inside a \parbox. – John Kormylo Aug 8 '14 at 22:51
  • I have edited my question, including your solution. I have a new problem, it seems related. When I get to page 2, it doesn't align the text properly. I provided a MWE. – Zool Aug 11 '14 at 23:30
  • @Zool - The problem is that when \testpage executes it is still on page one. It doesn't move to page two until the paragraph is completed. There might be a fix, or you could just add a \newpage before the start of the paragraph. – John Kormylo Aug 12 '14 at 0:49
  • @Zool - I fixed the page 2 problem. I also modified it to automatically unalign in order to fit the page (as in 4). – John Kormylo Aug 13 '14 at 3:57

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.