有时候我们需要编排中英文对照的文档,通常的做法是分为两栏来处理。LaTeX中分栏的方法有几种,这里介绍使用parallel宏包的方法,直接看实例。
操作系统:Ubuntu 18.04 编辑工具:TeXstudio 2.12.6 编译方式:LuaLaTeX
源码:
% 开源中国,陆巍
\documentclass{article}%
%
% 注意宏包顺序,有可能会报错
\usepackage{ctex}% 中文支持
\usepackage{geometry}% 用于页面设置
\usepackage{graphics}% 图形支持
\usepackage{parallel}% 提供双栏排版支持
\usepackage[english]{babel}% 载入美式英语断字模板
% 设置为A4纸,并设置边距
\geometry
{
a4paper,%
left = 1.5cm,%
right = 1.5cm,%
top = 2.54cm,%
bottom = 2.54cm%
}%
\setlength{\parindent}{2em}% 缩进为两个字符宽度
%
\setmainfont{Ubuntu Mono}% 设置全局英文字体
% ------------------ 开始 -------------------
%
\begin{document}%
\begin{Parallel}{82mm}{82mm}
\ParallelLText
{
\noindent\large\itshape 2.3 Modeling and Code Generation\\
}
\ParallelRText
{
\large\itshape 2.3 建模和代码生成
}
\ParallelPar
\ParallelLText
{
\noindent\large\textbf{\textit{XML Specifications}}: F Prime defines an Extensible Markup Language (XML) schema. Using the schema, you can specify a model of a FSW application. The model describes the application at a high level in terms of the components, ports, and topologies of the F Prime architecture (§ 2.1). The F Prime autocoder translates the model into the C++ classes described in § 2.2.\\
}
\ParallelRText
{
\textbf{XML规范}:F Prime定义了可扩展标记语言(XML)模式。使用该架构,可以指定FSW应用程序的模型。该模型从F Prime架构的组件、端口和拓扑(第2.1节)的高度描述了该应用程序。F Prime自动编码器将模型转换为第2.2节中描述的C++类。
}
\ParallelPar
\begin{center}
\includegraphics[width=16cm]{image/figure4.png}\\%
Figure 4: XML Port Specification
\includegraphics[width=16cm]{image/figure5.png}\\%
Figure 5: XML Component Specification
\end{center}
\ParallelLText
{
\noindent Figures 4 and 5 show example XML files for specifying F Prime ports and components. These examples are adapted from the CmdDispatcher component in the F Prime distribution (see § 2.4).
}
\ParallelRText
{
图4和5显示了用于指定F Prime端口和组件的示例XML文件。这些示例改编自F Prime发行版中的CmdDispatcher组件(请参见第2.4节)。
}
\end{Parallel}
\end{document}
效果如下:
注意事项:
- \begin{Parallel}{82mm}{82mm}语句后面的两个尺寸是左右两栏的宽度;
- 在段落之间一定要加上\ParallelPar语句,否则只会显示最后一段,包括图片前也要加入;
- 有些语句在\ParallelLText{}、\ParallelRText{}中显示有问题,例如枚举、编号语句,使用时要注意。