使用 \parbox 进行自定义设计时段落间距不一致

使用 \parbox 进行自定义设计时段落间距不一致

我正在开展一个项目,需要从包含转录对话的 JSON 文件以编程方式生成乳胶代码。最终目标的设计是非标准的。它要求所涉及的两个主题以类似于脚本的方式插入他们的答案,如附件示例中所示。我遇到的困难是,我无法找到实现该设计的令人满意的解决方案,因为 \minipage 或 \parbox 方法似乎会导致段落间距不一致(例如,参见附图中第二页左侧的段落)

在此处输入图片描述 在此处输入图片描述

我可能以错误的方式执行此操作,但由于源数据非常大并且需要生成 LaTeX 代码,我无法为左侧的所有文本设置一个小型页面,为右侧设置另一个小型页面,因为输入可能是未知的(从网站上动态获取)。

似乎我被迫为每个文本输入创建一个 parbox,然后需要将其放在页面的左侧或右侧,如下面的代码示例所示:

\documentclass{book}
\usepackage[english]{babel}

\usepackage[ 
paperwidth = 280mm, 
paperheight = 220mm,
layouthoffset = 3mm, 
layoutvoffset = 3mm,
top = 16mm,
bottom = 31mm,
left = 19mm,
right = 19mm]{geometry}

\usepackage{marginnote}

\newcommand\msgL[2]{
    \reversemarginpar \marginnote{\emph{\textsuperscript{#2}}}
    \raggedright \parbox{9.6cm}{#1} \par
}

\newcommand\msgR[2]{
    \normalmarginpar \marginnote{\emph{\textsuperscript{#2}}}
    \raggedleft \parbox{9.6cm}{\raggedleft #1} \par
}

\begin{document}

\fontsize{12pt}{15pt}\selectfont

\msgL{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore}{Name1} 
\msgR{Lorem ipsum}{Name2}
\msgR{Lorem ipsum dolor sit amet consectetur}{}
\msgR{Lorem ipsum dolor sit amet}{}
\msgL{Lorem ipsum dolor}{}
\msgR{Lorem ipsum dolor sit amet, consectetur}{}
\msgR{Lorem ipsum dolor sit}{}
\msgL{Lorem}{}
\msgR{Lorem ipsum dolor}{}
\msgR{Lorem ipsum dolor}{}
\msgR{Lorem ipsum dolor sit amet, consectetur}{}
\msgL{Lorem ipsum dolor sit amet}{}
\msgR{Lorem ipsum}{}
\msgR{Lorem ipsum dolor sit amet, consectetur adipiscing}{}
\msgR{Lorem ipsum dolor}{}
\msgL{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Viverra justo nec ultrices dui sapien eget mi. Ut tellus elementum sagittis vitae et leo duis ut diam. Placerat in egestas erat imperdiet. Turpis massa sed}{}
\msgR{Lorem ipsum dolor sit amet, consectetur}{}
\msgL{\textit{Lorem ipsum dolor sit amet}}{}
\msgR{Lorem ipsum dolor sit amet, consectetur}{}
\msgR{Lorem ipsum dolor}{}
\msgL{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod}{}
\msgR{Lorem ipsum dolor}{}
\msgL{\textit{Lorem ipsum dolor sit amet}}{}
\msgR{Lorem ipsum dolor sit amet, }{}
\msgR{Lorem ipsum dolor sit amet, }{}
\msgL{\textit{Lorem ipsum dolor sit amet}}{}
\msgR{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor}{}
\msgL{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Viverra justo nec ultrices dui sapien eget mi. Ut tellus elementum}{}
\msgL{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod}{}
\msgL{Lorem ipsum dolor sit amet}{}
\msgR{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt}{}
\msgR{Lorem ipsum dolor sit amet}{}
\msgL{Lorem ipsum dolor sit amet, consectetur adipiscing elit}{}
\msgL{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt}{}
\msgR{Lorem}{}
\msgR{Lorem ipsum dolor sit amet}{}
\msgR{Lorem ipsum dolor sit amet, consectetur}{}
\msgL{Lorem ipsum dolor sit amet, consectetur}{}
\msgL{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.}{}
\msgR{Lorem ipsum dolor sit amet, consectetur adipiscing elit}{}
\msgL{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna}{}
\msgR{Lorem}{}
\msgR{Lorem ipsum}{}
\msgR{\textit{Lorem ipsum dolor sit amet}}{}

\end{document}

如果知道是否有适当的方法可以实现这一点,并且可以在所描述的条件下扩展到大量输入数据,那就太好了。非常感谢!

答案1

以下是一些可能有帮助的想法。

  • 该软件包paracol用于按列排版材料,并在列之间来回切换。您还可以将一列或两列对齐排版。

  • 您可以将名称设为可选参数。不确定这是否会让自动创建对话变得更轻松。

  • 如果边注造成问题,您可以使用普通框。在左侧,以

    \makebox[0pt][r]{\scriptsize\emph{#1}\quad}
    

    右侧

    \makebox[0pt][l]{\quad\scriptsize\emph{#1}}\\[-\baselineskip]
    

下面代码中的相关定义是:

\usepackage{paracol}

\newenvironment{conversation}{%
  \begin{paracol}{2}
    \fontsize{12pt}{15pt}\selectfont
}{%
  \end{paracol}
}

\newcommand\msgL[2][]{%
  \begin{leftcolumn*}\raggedright
    \makebox[0pt][r]{\scriptsize\emph{#1}\quad}#2
  \end{leftcolumn*}
}

\newcommand\msgR[2][]{%
  \begin{rightcolumn*}\raggedleft
    \makebox[0pt][l]{\quad\scriptsize\emph{#1}}\\[-\baselineskip]
    #2
  \end{rightcolumn*}
}

在此处输入图片描述

\documentclass{book}
\usepackage[english]{babel}

\usepackage[ 
paperwidth = 280mm, 
paperheight = 220mm,
layouthoffset = 3mm, 
layoutvoffset = 3mm,
top = 16mm,
bottom = 31mm,
left = 19mm,
right = 19mm]{geometry}

\usepackage{paracol}

\newenvironment{conversation}{%
  \begin{paracol}{2}
    \fontsize{12pt}{15pt}\selectfont
}{%
  \end{paracol}
}

\newcommand\msgL[2][]{%
  \begin{leftcolumn*}\raggedright
    \makebox[0pt][r]{\scriptsize\emph{#1}\quad}#2
  \end{leftcolumn*}
}

\newcommand\msgR[2][]{%
  \begin{rightcolumn*}\raggedleft
    \makebox[0pt][l]{\quad\scriptsize\emph{#1}}\\[-\baselineskip]
    #2
  \end{rightcolumn*}
}

\begin{document}
\begin{conversation}
\msgL[Name1]{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore}
\msgR[Name2]{Lorem ipsum}
\msgR{Lorem ipsum dolor sit amet consectetur}
\msgR{Lorem ipsum dolor sit amet}
\msgL{Lorem ipsum dolor}
\msgR{Lorem ipsum dolor sit amet, consectetur}
\msgR{Lorem ipsum dolor sit}
\msgL{Lorem}
\msgR{Lorem ipsum dolor}
\msgR{Lorem ipsum dolor}
\msgR{Lorem ipsum dolor sit amet, consectetur}
\msgL{Lorem ipsum dolor sit amet}
\msgR{Lorem ipsum}
\msgR{Lorem ipsum dolor sit amet, consectetur adipiscing}
\msgR{Lorem ipsum dolor}
\msgL{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Viverra justo nec ultrices dui sapien eget mi. Ut tellus elementum sagittis vitae et leo duis ut diam. Placerat in egestas erat imperdiet. Turpis massa sed}
\msgR{Lorem ipsum dolor sit amet, consectetur}
\msgL{\textit{Lorem ipsum dolor sit amet}}
\msgR{Lorem ipsum dolor sit amet, consectetur}
\msgR{Lorem ipsum dolor}
\msgL{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod}
\msgR{Lorem ipsum dolor}
\msgL{\textit{Lorem ipsum dolor sit amet}}
\msgR{Lorem ipsum dolor sit amet, }
\msgR{Lorem ipsum dolor sit amet, }
\msgL{\textit{Lorem ipsum dolor sit amet}}
\msgR{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor}
\msgL{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Viverra justo nec ultrices dui sapien eget mi. Ut tellus elementum}
\msgL{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod}
\msgL{Lorem ipsum dolor sit amet}
\msgR{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt}
\msgR{Lorem ipsum dolor sit amet}
\msgL{Lorem ipsum dolor sit amet, consectetur adipiscing elit}
\msgL{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt}
\msgR{Lorem}
\msgR{Lorem ipsum dolor sit amet}
\msgR{Lorem ipsum dolor sit amet, consectetur}
\msgL{Lorem ipsum dolor sit amet, consectetur}
\msgL{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.}
\msgR{Lorem ipsum dolor sit amet, consectetur adipiscing elit}
\msgL{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna}
\msgR{Lorem}
\msgR{Lorem ipsum}
\msgR{\textit{Lorem ipsum dolor sit amet}}
\end{conversation}
\end{document}

编辑:在评论中,John Kormylo 建议将边注排版成另外两栏,就像他在他对“\marginpar 从页面顶部开始”的回答通过这种方法,paracol包管理两个窄列和两个宽列,定义如下。

\usepackage{paracol}
\columnratio{0.1,0.4,0.4,0.1}

\newenvironment{conversation}{%
  \begin{paracol}{4}
    \fontsize{12pt}{15pt}\selectfont
}{%
  \end{paracol}
}

\newcommand\msgL[2][]{%
  \begin{nthcolumn*}{1}\raggedright#2\end{nthcolumn*}
  \begin{nthcolumn}{0}\raggedleft\scriptsize\emph{#1}\quad\end{nthcolumn}
}

\newcommand\msgR[2][]{%
  \begin{nthcolumn*}{2}\raggedleft#2\end{nthcolumn*}
  \begin{nthcolumn}{3}\raggedright\scriptsize\emph{#1}\quad\end{nthcolumn}
}

相关内容