有時候我們需要編排中英文對照的文檔,通常的做法是分爲兩欄來處理。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{}中顯示有問題,例如枚舉、編號語句,使用時要注意。