LaTeXテーブル
このシリーズの記事は@YhL_Leo出品、転載は出典を明記してください.
記事リンク:http://blog.csdn.net/yhl_leo/article/details/50066137
いくつかのLaTeXの表の使用方法は以下の通りです.
1.table
2.tabular
例の中の
left-justified column
centered column
right-justified column
bottom
center (default)
top
paragraph column with text vertically aligned at the top
paragraph column with text vertically aligned in the middle (requires array package)
paragraph column with text vertically aligned at the bottom (requires array package)
vertical line
double vertical line
また、一般的なコマンドもあります.
column separator
start new row (additional space may be specified after
horizontal line
start a new line within a cell (in a paragraph column)
start a new line within a cell (in a paragraph column) instead of
partial horizontal line beginning in column
最も簡単な例外に加えて、次のことができます.
表に長いテキストがある場合は、そのまま並べておくと見苦しいだけでなく、ページの範囲を超えてしまう可能性があります.
また、マクロパケット
その中の位置合わせは
列の間隔を調整するには、コマンドを使用します.
もう1つの方法は、
他の使用法は、ある行の後ろに一定の間隔を空けるようにします.
一部のLaTeXの環境では、テーブルに挿入することもできます.
列仕様設定コマンドの使用:
@-expressionsの使い方:
行の特別な設定は、いくつかの例を示します.
3.booktabs
すなわち、三線表:
4.colortbl
よく使う表の塗り
5.diagbox
斜線ヘッダーを描くバッグ
参照先:了解乎:http://zhuanlan.zhihu.com/LaTeX/19749566 ウィキ:https://en.wikibooks.org/wiki/LaTeX/Tables#Text_wrapping_in_tables
記事リンク:http://blog.csdn.net/yhl_leo/article/details/50066137
いくつかのLaTeXの表の使用方法は以下の通りです.
1.table
\documentclass{article}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{|l|c|c|}\hline
Setting&\multicolumn{2}{c|}{A4 size paper}\\\hline
&mm&inches\\
Top&25&1.0\\
Bottom&25&1.0\\
Left&20&0.8\\
Right&20&0.8\\
Column Width&82&3.2\\
Column Spacing&6&0.25\\\hline
\end{tabular}
\caption{Margin settings for A4 size paper}
\label{tab:Margin_settings}
\end{table}
\end{document}
2.tabular
\begin{tabular}{|c|c|c|}
\hline 2&9&4\\
\hline 7&5&3\\
\hline 6&1&8\\
\hline
\end{tabular}
例の中の
|c|
のように、その場所を導言区と呼び、表の各列の属性を約束します.l
left-justified column
c
centered column
r
right-justified column
b
bottom
c
center (default)
t
top
p{'width'}
paragraph column with text vertically aligned at the top
m{'width'}
paragraph column with text vertically aligned in the middle (requires array package)
b{'width'}
paragraph column with text vertically aligned at the bottom (requires array package)
|
vertical line
||
double vertical line
また、一般的なコマンドもあります.
&
column separator
\\
start new row (additional space may be specified after
\\
using square brackets, such as \\[6pt]
\hline
horizontal line
ewline
start a new line within a cell (in a paragraph column)
\tabularnewline
start a new line within a cell (in a paragraph column) instead of
\\
to avoid a Misplaced
oalign
error in the tabular \cline{i-j}
partial horizontal line beginning in column
i
and ending in column j
最も簡単な例外に加えて、次のことができます.
% example 1:
\begin{center}
\begin{tabular}{ | l || c || r }
\hline
1 & 2 & 3 \\ \hline
4 & 5 & 6 \\ \hline \hline
7 & 8 & 9 \\
\hline
\end{tabular}
\end{center}
example 1
% example 2:
%\multicolumn{n}{format}{item}
\begin{tabular}{|c|c|c|}
\hline \multicolumn{3}{|c|}{?}\\
\hline 7&5&3\\
\hline 6&1&8\\
\hline
\end{tabular}
example 2
% example 3:
\begin{tabular}{|r|l|}
\hline
7C0 & hexadecimal \\
3700 & octal \\ \cline{2-2}
11111000000 & binary \\
\hline \hline
1984 & decimal \\
\hline
\end{tabular}
example 3
array
環境(使用時に含む必要がある:\usepackage{array}
)では、tabular環境を再実現し、多くの新しいオプションを追加しました.tabular
の最初の例を少し修正すると、array
パケットを含まない場合と含まない場合では効果が異なることがわかります.% example 1:
%\usepackage{array}
\tabcolsep20pt
\arrayrulewidth2pt
\begin{tabular}{*{3}{|c}|}
%\begin{tabular}{|c|c|c|}
\hline 2&9&4\\
\hline 7&5&3\\
\hline 6&1&8\\
\hline
\end{tabular}
% example 2:
...
\usepackage{array}
...
\tabcolsep20pt
\arrayrulewidth2pt
\begin{tabular}{*{3}{|c}|}
%\begin{tabular}{|c|c|c|}
\hline 2&9&4\\
\hline 7&5&3\\
\hline 6&1&8\\
\hline
\end{tabular}
example 1
example 2
表に長いテキストがある場合は、そのまま並べておくと見苦しいだけでなく、ページの範囲を超えてしまう可能性があります.
Without specifying width for last column:
\begin{center}
\begin{tabular}{| l | l | l | l |}
\hline
Day & Min Temp & Max Temp & Summary \\ \hline
Monday & 11C & 22C & A clear day with lots of sunshine.
However, the strong breeze will bring down the temperatures. \\ \hline
Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
across most of Scotland and Northern Ireland,
but rain reaching the far northwest. \\ \hline
Wednesday & 10C & 21C & Rain will still linger for the morning.
Conditions will improve by early afternoon and continue
throughout the evening. \\
\hline
\end{tabular}
\end{center}
With width specified:
\begin{center}
\begin{tabular}{ | l | l | l | p{5cm} |}
\hline
Day & Min Temp & Max Temp & Summary \\ \hline
Monday & 11C & 22C & A clear day with lots of sunshine.
However, the strong breeze will bring down the temperatures. \\ \hline
Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
across most of Scotland and Northern Ireland,
but rain reaching the far northwest. \\ \hline
Wednesday & 10C & 21C & Rain will still linger for the morning.
Conditions will improve by early afternoon and continue
throughout the evening. \\
\hline
\end{tabular}
\end{center}
また、マクロパケット
tabulary
を用いても実現できる.\usepackage{tabulary}
...
\begin{center}
\begin{tabulary}{0.7\textwidth}{LCL}
Short sentences & \# & Long sentences \\
\hline
This is short. & 173 & This is much loooooooonger, because there are many more words. \\
This is not shorter. & 317 & This is still loooooooonger, because there are many more words. \\
\end{tabulary}
\end{center}
その中の位置合わせは
L
, C
のほか、R
, J
. \parbox
の使い方を見てみましょう.文を表の形式に分割したい場合は、次のようにします.\begin{tabular}{cc}
boring cell content & \parbox[t]{5cm}{rather long par\
ew par}
\end{tabular}
列の間隔を調整するには、コマンドを使用します.
\setlength{\tabcolsep}{5pt} %colums, default value is 6pt
\renewcommand{\arraystretch}{1.5} %rows, default value is 1.0
もう1つの方法は、
\hline
およびcline{i-j}
の後に
oalign{\smallskip}
を追加することであり、例えば、\begin{center}
\begin{tabular}{ | l | l | r | }
\hline
\multicolumn{2}{c}{Item} \\
\cline{1-2}
Animal & Description & Price (\$) \\
\hline
Gnat & per gram & 13.65 \\
& each & 0.01 \\
Gnu & stuffed & 92.50 \\
Emu & stuffed & 33.33 \\
Armadillo & frozen & 8.99 \\
\hline
\end{tabular}
example 1
$ $
\setlength{\tabcolsep}{4pt}
\begin{tabular}{ | l | l | r | }
\hline
\multicolumn{2}{c}{Item} \\
\cline{1-2}
Animal & Description & Price (\$) \\
\hline
Gnat & per gram & 13.65 \\
& each & 0.01 \\
Gnu & stuffed & 92.50 \\
Emu & stuffed & 33.33 \\
Armadillo & frozen & 8.99 \\
\hline
\end{tabular}
example 2
$ $
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{ | l | l | r | }
\hline
\multicolumn{2}{c}{Item} \\
\cline{1-2}
Animal & Description & Price (\$) \\
\hline
Gnat & per gram & 13.65 \\
& each & 0.01 \\
Gnu & stuffed & 92.50 \\
Emu & stuffed & 33.33 \\
Armadillo & frozen & 8.99 \\
\hline
\end{tabular}
example 3
$ $
\setlength{\tabcolsep}{6pt}
\renewcommand{\arraystretch}{1.0}
\begin{tabular}{ | l | l | r | }
\hline
oalign{\smallskip}
\multicolumn{2}{c}{Item} \\
\cline{1-2}
oalign{\smallskip}
Animal & Description & Price (\$) \\
oalign{\smallskip}\hline
oalign{\smallskip}
Gnat & per gram & 13.65 \\
& each & 0.01 \\
Gnu & stuffed & 92.50 \\
Emu & stuffed & 33.33 \\
Armadillo & frozen & 8.99 \\
oalign{\smallskip}\hline
\end{tabular}
example 4
\end{center}
他の使用法は、ある行の後ろに一定の間隔を空けるようにします.
\begin{tabular}{ll}
\hline
Mineral & Color \\[0.5cm]
Ruby & red \\
Sapphire & blue \\
\hline
\end{tabular}
一部のLaTeXの環境では、テーブルに挿入することもできます.
\begin{tabular}{m{5cm} c} % here the m can be replaced by p or b.
\\ \hline
\begin{verbatim}
I love coding
\end{verbatim}
& LaTeX
\\ \hline
\end{tabular}
列仕様設定コマンドの使用:
>{\cmd} and <{\cmd}
テーブルの文字が数学的手書きフォントである場合:...
\usepackage{array}
...
ewcolumntype{F}{>{$}c<{$}}
\begin{tabular}{FFF}
\alpha & \beta & \gamma \\
\delta & \epsilon & \upsilon \\
\sigma & \tau & \phi \\
\end{tabular}
@-expressionsの使い方:
\begin{tabular}{|@{}l|l@{}|}
\hline
stuff & stuff \\ \hline
stuff & stuff \\
\hline
\end{tabular}
\begin{tabular}{r@{.}l}
3 & 14159 \\
16 & 2 \\
123 & 456 \\
\end{tabular}
行の特別な設定は、いくつかの例を示します.
\begin{tabular}{ |l|l| }
\hline
\multicolumn{2}{|c|}{Team sheet} \\
\hline
GK & Paul Robinson \\
LB & Lucas Radebe \\
DC & Michael Duberry \\
DC & Dominic Matteo \\
RB & Dider Domi \\
MC & David Batty \\
MC & Eirik Bakke \\
MC & Jody Morris \\
FW & Jamie McMaster \\
ST & Alan Smith \\
ST & Mark Viduka \\
\hline
\end{tabular}
...
\usepackage{multirow}
...
\begin{tabular}{ |l|l|l| }
\hline
\multicolumn{3}{ |c| }{Team sheet} \\
\hline
Goalkeeper & GK & Paul Robinson \\ \hline
\multirow{4}{*}{Defenders} & LB & Lucas Radebe \\
& DC & Michael Duburry \\
& DC & Dominic Matteo \\
& RB & Didier Domi \\ \hline
\multirow{3}{*}{Midfielders} & MC & David Batty \\
& MC & Eirik Bakke \\
& MC & Jody Morris \\ \hline
Forward & FW & Jamie McMaster \\ \hline
\multirow{2}{*}{Strikers} & ST & Alan Smith \\
& ST & Mark Viduka \\
\hline
\end{tabular}
...
\usepackage{multirow}
...
\begin{tabular}{cc|c|c|c|c|l}
\cline{3-6}
& & \multicolumn{4}{ c| }{Primes} \\ \cline{3-6}
& & 2 & 3 & 5 & 7 \\ \cline{1-6}
\multicolumn{1}{ |c }{\multirow{2}{*}{Powers} } &
\multicolumn{1}{ |c| }{504} & 3 & 2 & 0 & 1 & \\ \cline{2-6}
\multicolumn{1}{ |c }{} &
\multicolumn{1}{ |c| }{540} & 2 & 3 & 1 & 0 & \\ \cline{1-6}
\multicolumn{1}{ |c }{\multirow{2}{*}{Powers} } &
\multicolumn{1}{ |c| }{gcd} & 2 & 2 & 0 & 0 & min \\ \cline{2-6}
\multicolumn{1}{ |c }{} &
\multicolumn{1}{ |c| }{lcm} & 3 & 3 & 1 & 1 & max \\ \cline{1-6}
\end{tabular}
\begin{tabular}{ r|c|c| }
\multicolumn{1}{r}{}
& \multicolumn{1}{c}{noninteractive}
& \multicolumn{1}{c}{interactive} \\
\cline{2-3}
massively multiple & Library & University \\
\cline{2-3}
one-to-one & Book & Tutor \\
\cline{2-3}
\end{tabular}
3.booktabs
すなわち、三線表:
\usepackage{booktabs}
\begin{tabular}{ccc}
\toprule
2&9&4\\
\midrule
7&5&3\\
6&1&8\\
\bottomrule
\end{tabular}
4.colortbl
よく使う表の塗り
colortbl
バッグ:% example 1:
\usepackage{colortbl}
\begin{tabular}{ccc}
\rowcolor[gray]{.9}
2&9&4\\
\rowcolor[gray]{.8}
7&5&3\\
\rowcolor[gray]{.7}
6&1&8\\
\end{tabular}
example 1
% example 2:
\begin{tabular}
{>{\columncolor[gray]{.9}}c|
>{\columncolor[gray]{.8}}c|
>{\columncolor[gray]{.7}}c}
2&9&4\\
7&5&3\\
6&1&8\\
\end{tabular}
example 2
%example 3:
\begin{tabular}{ccc}
\cellcolor[rgb]{.9,.9,.9}2&
\cellcolor[rgb]{.8,.9,.9}9&
\cellcolor[rgb]{.7,.9,.9}4\\
\cellcolor[rgb]{.9,.8,.9}7&
\cellcolor[rgb]{.8,.8,.9}5&
\cellcolor[rgb]{.7,.8,.9}3\\
\cellcolor[rgb]{.9,.7,.9}6&
\cellcolor[rgb]{.8,.7,.9}1&
\cellcolor[rgb]{.7,.7,.9}8\\
\end{tabular}
example 3
5.diagbox
斜線ヘッダーを描くバッグ
diagbox
\usepackage{diagbox}
...
\begin{tabular}{|l|ccc|}
\hline
\diagbox{Time}{Room}{Day} & Mon & Tue & Wed \\
\hline
Morning & used & used & \\
Afternoon & & used & used \\
\hline
\end{tabular}
参照先: