mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-23 21:20:42 +08:00
The translation completes a part
This commit is contained in:
parent
acf01f6230
commit
4f42b0ae3f
@ -7,239 +7,200 @@
|
||||
[#]: via: (https://fedoramagazine.org/latex-typesetting-part-2-tables/)
|
||||
[#]: author: (Earl Ramirez https://fedoramagazine.org/author/earlramirez/)
|
||||
|
||||
LaTeX typesetting part 2 (tables)
|
||||
LaTex 排版(2):表格
|
||||
======
|
||||
|
||||
![][1]
|
||||
|
||||
LaTeX offers a number of tools to create and customise tables, in this series we will be using the tabular and tabularx environment to create and customise tables.
|
||||
LaTeX 提供了许多工具来创建和定制表格,在本系列中,我们将使用 tabular 和 tabularx 环境来创建和定制表。
|
||||
|
||||
### Basic table
|
||||
### 基础表格
|
||||
|
||||
To create a table you simply specify the environment \begin{tabular}{columns}
|
||||
```
|
||||
要创建表,只需指定环境 `\begin{tabular}{列选项}`
|
||||
|
||||
```
|
||||
|
||||
\begin{tabular}{c|c}
|
||||
Release &Codename \\\ \hline
|
||||
Fedora Core 1 &Yarrow \\\
|
||||
Fedora Core 2 &Tettnang \\\
|
||||
Fedora Core 3 &Heidelberg \\\
|
||||
Fedora Core 4 &Stentz \\\
|
||||
Release &Codename \\ \hline
|
||||
Fedora Core 1 &Yarrow \\
|
||||
Fedora Core 2 &Tettnang \\
|
||||
Fedora Core 3 &Heidelberg \\
|
||||
Fedora Core 4 &Stentz \\
|
||||
\end{tabular}
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
![Basic Table][2]
|
||||
|
||||
In the above example "{c|c}" in the curly bracket refers to the position of the text in the column. The below table summarises the positional argument together with the description.
|
||||
在上面的示例中,花括号中的”{c|c}”表示文本在列中的位置。下表总结了位置参数及其说明。
|
||||
|
||||
Position | Argument
|
||||
---|---
|
||||
c | Position text in the centre
|
||||
l | Position text left-justified
|
||||
r | Position text right-justified
|
||||
p{width} | Align the text at the top of the cell
|
||||
m{width} | Align the text in the middle of the cell
|
||||
b{width} | Align the text at the bottom of the cell
|
||||
参数 | 位置
|
||||
|:---:|:---
|
||||
c | 将文本置于中间
|
||||
l | 将文本左对齐
|
||||
r | 将文本右对齐
|
||||
p{width} | 文本对齐单元格顶部
|
||||
m{width} | 文本对齐单元格中间
|
||||
b{width} | 文本对齐单元格底部
|
||||
|
||||
>Both m{width} and b{width} requires the array package to be specified in the preamble.
|
||||
> m{width} 和 b{width} 都要求在最前面指定数组包。
|
||||
|
||||
Using the example above, let us breakdown the important points used and describe a few more options that you will see in this series
|
||||
使用上面的例子,让我们来详细讲解使用的要点,并描述您将在本系列中看到的更多选项
|
||||
|
||||
Option | Description
|
||||
---|---
|
||||
& | Defines each cell, the ampersand is only used from the second column
|
||||
\ | This terminates the row and start a new row
|
||||
|
|
||||
\hline | Specifies the horizontal line (optional)
|
||||
*{num}{form} | This is handy when you have many columns and is an efficient way of limiting the repetition
|
||||
|
|
||||
选项 | 意义
|
||||
|:-:|:-|
|
||||
& | 定义每个单元格,这个符号仅用于第二列
|
||||
\ | 这将终止该行并开始一个新行
|
||||
\| | 指定表格中的垂直线(可选)
|
||||
\hline | 指定表格中水平线(可选)
|
||||
*{num}{form} | 当您有许多列时,可以使用这个,并且是限制重复的有效方法
|
||||
\|\| | 指定表格中垂直双线
|
||||
|
||||
### Customising our table
|
||||
### 定制表格
|
||||
|
||||
Now that some of the options available let create a table using the options described in the previous section.
|
||||
```
|
||||
学会了这些选项,让我们使用这些选项创建一个表。
|
||||
|
||||
```
|
||||
|
||||
\begin{tabular}{*{3}{|l|}}
|
||||
\hline
|
||||
\textbf{Version} &\textbf{Code name} &\textbf{Year released} \\\
|
||||
\textbf{Version} &\textbf{Code name} &\textbf{Year released} \\
|
||||
\hline
|
||||
Fedora 6 &Zod &2006 \\\ \hline
|
||||
Fedora 7 &Moonshine &2007 \\\ \hline
|
||||
Fedora 8 &Werewolf &2007 \\\
|
||||
Fedora 6 &Zod &2006 \\ \hline
|
||||
Fedora 7 &Moonshine &2007 \\ \hline
|
||||
Fedora 8 &Werewolf &2007 \\
|
||||
\hline
|
||||
\end{tabular}
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
![Customise Table][3]
|
||||
|
||||
### Managing long text
|
||||
### 管理长文本
|
||||
|
||||
With LaTeX if there are many texts in a column it will not be formatted well and does not look presentable.
|
||||
如果列中有很多文本,那么它的格式就不好处理,看起来也不好看。
|
||||
|
||||
The below example shows how long text is formatted, we will use "blindtext" in the preamble so that we can produce sample text.
|
||||
```
|
||||
下面的示例显示了文本的格式长度,我们将在导言区中使用 “blindtext”,以便生成示例文本。
|
||||
|
||||
```
|
||||
|
||||
\begin{tabular}{|l|l|}\hline
|
||||
Summary &Description \\\ \hline
|
||||
Test &\blindtext \\\
|
||||
Summary &Description \\ \hline
|
||||
Test &\blindtext \\
|
||||
\end{tabular}
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
![Default Formatting][4]
|
||||
|
||||
As you can see the text exceed the page width; however, there are a couple of options to overcome this challenge.
|
||||
正如您所看到的,文本超出了页面宽度;但是,有几个选项可以克服这个问题。
|
||||
|
||||
* Specify the column width, for example, m{5cm}
|
||||
* Utilise the tabularx environment, this requires tabularx package in the preamble.
|
||||
* 指定列宽,例如 m{5cm}
|
||||
* 利用 TABLARX 环境,这需要在导言区中引用 TABLARX 宏包。
|
||||
|
||||
|
||||
#### 使用列宽管理长文本
|
||||
|
||||
### Managing long text with column width
|
||||
|
||||
By specifying the column width the text will be wrapped into the width as shown in the example below.
|
||||
```
|
||||
通过指定列宽,文本将被包装为如下示例所示的宽度。
|
||||
|
||||
```
|
||||
|
||||
\begin{tabular}{|l|m{14cm}|} \hline
|
||||
Summary &Description \\\ \hline
|
||||
Test &\blindtext \\\ \hline
|
||||
Summary &Description \\ \hline
|
||||
Test &\blindtext \\ \hline
|
||||
\end{tabular}\vspace{3mm}
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
![Column width][5]
|
||||
|
||||
### Managing long text with tabularx
|
||||
#### 使用 tabularx 管理长文本
|
||||
|
||||
Before we can leverage tabularx we need to add it in the preamble. Tabularx takes the following example
|
||||
在我们利用表格之前,我们需要在导言区中加上它。TABLARX 方法见以下示例
|
||||
|
||||
`\begin{tabularx}{宽度}{列选项}`
|
||||
|
||||
**\begin{tabularx}{width}{columns}**
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
\begin{tabularx}{\textwidth}{|l|X|} \hline
|
||||
Summary & Tabularx Description\\\ \hline
|
||||
Text &\blindtext \\\ \hline
|
||||
Summary & Tabularx Description\\ \hline
|
||||
Text &\blindtext \\ \hline
|
||||
\end{tabularx}
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
![Tabularx][6]
|
||||
|
||||
Notice that the column that we want the long text to be wrapped has a capital "X" specified.
|
||||
请注意,我们需要处理长文本的列在花括号中指定了大写“X”。
|
||||
|
||||
### Multirow and multicolumn
|
||||
### 合并行合并列
|
||||
|
||||
There are times when you will need to merge rows and/or column. This section describes how it is accomplished. To use multirow and multicolumn add multirow to the preamble.
|
||||
有时需要合并行或列。本节描述了如何完成。要使用 multirow 和 multicolumn,请将 multirow 添加到导言区。
|
||||
|
||||
### Multirow
|
||||
#### 合并行
|
||||
|
||||
Multirow takes the following argument _\multirow{number_of_rows}{width}{text}_, let us look at the below example.
|
||||
```
|
||||
Multirow 采用以下参数`\multirow{行的数量}{宽度}{文本}`,让我们看看下面的示例。
|
||||
|
||||
```
|
||||
|
||||
\begin{tabular}{|l|l|}\hline
|
||||
Release &Codename \\\ \hline
|
||||
Fedora Core 4 &Stentz \\\ \hline
|
||||
\multirow{2}{*}{MultiRow} &Fedora 8 \\\
|
||||
&Werewolf \\\ \hline
|
||||
Release &Codename \\ \hline
|
||||
Fedora Core 4 &Stentz \\ \hline
|
||||
\multirow{2}{*}{MultiRow} &Fedora 8 \\
|
||||
&Werewolf \\ \hline
|
||||
\end{tabular}
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
![MultiRow][7]
|
||||
|
||||
In the above example, two rows were specified, the ‘*’ tells LaTeX to automatically manage the size of the cell.
|
||||
在上面的示例中,指定了两行,'*'告诉LaTeX自动管理单元格的大小。
|
||||
|
||||
### Multicolumn
|
||||
#### 合并列
|
||||
|
||||
Multicolumn argument is _\multicolumn{number_of_columns}{cell_position}{text}_, below example demonstrates multicolumn.
|
||||
```
|
||||
Multicolumn 参数是 `{Multicolumn{列的数量}{单元格选项}{位置}{文本}`,下面的示例演示 Multicolumn。
|
||||
|
||||
```
|
||||
|
||||
\begin{tabular}{|l|l|l|}\hline
|
||||
Release &Codename &Date \\\ \hline
|
||||
Fedora Core 4 &Stentz &2005 \\\ \hline
|
||||
\multicolumn{3}{|c|}{Mulit-Column} \\\ \hline
|
||||
Release &Codename &Date \\ \hline
|
||||
Fedora Core 4 &Stentz &2005 \\ \hline
|
||||
\multicolumn{3}{|c|}{Mulit-Column} \\ \hline
|
||||
\end{tabular}
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
![Multi-Column][8]
|
||||
|
||||
### Working with colours
|
||||
### 使用颜色
|
||||
|
||||
Colours can be assigned to the text, an individual cell or the entire row. Additionally, we can configure alternating colours for each row.
|
||||
可以为文本、单个单元格或整行指定颜色。此外,我们可以为每一行配置交替的颜色。
|
||||
|
||||
Before we can add colour to our tables we need to include _\usepackage[table]{xcolor}_ into the preamble. We can also define colours using the following colour reference [LaTeX Colour][9] or by adding an exclamation after the colour prefixed by the shade from 0 to 100. For example, _gray!30_
|
||||
```
|
||||
在给表添加颜色之前,我们需要在导言区引用 `\usepackage[table]{xcolor}`。我们还可以使用以下颜色参考 [LaTeX Color][9] 或在颜色前缀后面添加感叹号(从0到100的阴影)来定义颜色。例如,`gray!30`
|
||||
|
||||
```
|
||||
|
||||
\definecolor{darkblue}{rgb}{0.0, 0.0, 0.55}
|
||||
\definecolor{darkgray}{rgb}{0.66, 0.66, 0.66}
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
Below example demonstrate this a table with alternate colours, \rowcolors take the following options _\rowcolors{row_start_colour}{even_row_colour}{odd_row_colour}_.
|
||||
```
|
||||
下面的示例演示了一个具有各种颜色的表,`\rowcolors` 采用以下选项`\rowcolors{起始行颜色}{偶数行颜色}{奇数行颜色}`。
|
||||
|
||||
```
|
||||
|
||||
\rowcolors{2}{darkgray}{gray!20}
|
||||
\begin{tabular}{c|c}
|
||||
Release &Codename \\\ \hline
|
||||
Fedora Core 1 &Yarrow \\\
|
||||
Fedora Core 2 &Tettnang \\\
|
||||
Fedora Core 3 &Heidelberg \\\
|
||||
Fedora Core 4 &Stentz \\\
|
||||
Release &Codename \\ \hline
|
||||
Fedora Core 1 &Yarrow \\
|
||||
Fedora Core 2 &Tettnang \\
|
||||
Fedora Core 3 &Heidelberg \\
|
||||
Fedora Core 4 &Stentz \\
|
||||
\end{tabular}
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
![Alt colour table][10]
|
||||
|
||||
In addition to the above example, \rowcolor can be used to specify the colour of each row, this method works best when there are multi-rows. The following examples show the impact of using the \rowcolours with multi-row and how to work around it.
|
||||
除了上面的例子,`\rowcolor` 可以用来指定每一行的颜色,这个方法在有合并行时效果最好。以下示例显示将 `\rowColors` 与合并行一起使用的影响以及如何解决此问题。
|
||||
|
||||
![Impact on multi-row][11]
|
||||
|
||||
As you can see the _multi-row_ is visible in the first row, to fix this we have to do the following.
|
||||
```
|
||||
你可以看到,在合并行中,只有第一行能显示颜色。想要解决这个问题,需要这样做:
|
||||
|
||||
```
|
||||
|
||||
\begin{tabular}{|l|l|}\hline
|
||||
\rowcolor{darkblue}\textsc{\color{white}Release} &\textsc{\color{white}Codename} \\\ \hline
|
||||
\rowcolor{gray!10}Fedora Core 4 &Stentz \\\ \hline
|
||||
\rowcolor{gray!40}&Fedora 8 \\\
|
||||
\rowcolor{gray!40}\multirow{-2}{*}{Multi-Row} &Werewolf \\\ \hline
|
||||
\rowcolor{darkblue}\textsc{\color{white}Release} &\textsc{\color{white}Codename} \\ \hline
|
||||
\rowcolor{gray!10}Fedora Core 4 &Stentz \\ \hline
|
||||
\rowcolor{gray!40}&Fedora 8 \\
|
||||
\rowcolor{gray!40}\multirow{-2}{*}{Multi-Row} &Werewolf \\ \hline
|
||||
\end{tabular}
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
![Multi-row][12]
|
||||
|
||||
Let us discuss the changes that were implemented to resolve the multi-row with the alternate colour issue.
|
||||
|
Loading…
Reference in New Issue
Block a user