两列文本对齐:强制一列为空行,以避免另一列发生冲突

两列文本对齐:强制一列为空行,以避免另一列发生冲突

我有一个关于在两列中对齐文本的问题。这里有一个类似的问题:两列内容彼此相对定位,但我无法让示例解决方案运行,看看它是否能解决我的问题。我对 LaTeX 还很陌生,否则我会尝试编写一些代码来自己解决问题。

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.

结果不需要左列中的数字指示符,它们只是用来说明右侧的文本需要与哪个单词对齐。这是我试图实现的图像: 期望输出(ACT 英语部分)

我认为这是一个最小的工作示例:

\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}

其输出: MWE 的输出 谢谢

使用下面评论中的输入,我能够生成更高质量的输出。我在两页上使用它时遇到了问题。这是一个可重现的版本。当我到达第二页时,它会一直放在\columnnote页面底部。

\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}

答案1

此解决方案实际上从未使用第二列,但仍需要 paracol 或 parcolumn 来将第二列留空。您可以使用几何图形创建单个左列,但这更简单。

这里的关键是估计重叠的行数。在段落仍在构建时,无法准确计算此值。数字越小,行末的间隙越大。

需要注意的是,当在一行中间使用 \vspace 时,它​​直到下一行开始才会实现,因此间隙总会出现在包含 \columnnote 的行之后。

最后,通常需要运行两次才能得到一个好的页面。这是因为 tikz 使用 aux 文件来存储位置信息。

\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}

第 1 页


第2页

相关内容